简体   繁体   中英

Google Plus Sign-In button rendered but not working

I'm trying to get comfortable with the Google APIs.

To study the sign-in process, I built a simple web page to get the sign-in button working according to https://developers.google.com/+/web/signin/add-button and the button is rendered properly. However, it is not active - it doesn't react to clicks, there's also no error in the browser console.

I do not run the page from a web server, I'm opening it directly from disk. Ie the URL is something like file:///c:/projects/GooglePlusClientJS/google_plus_js.html .

The page code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">

  <script src="https://apis.google.com/js/client:platform.js" async defer></script>
  <script type="text/javascript">
function signinCallback(authResult) {
  if (authResult['status']['signed_in']) {
    // Update the app to reflect a signed in user
    // Hide the sign-in button now that the user is authorized, for example:
    console.log("Signed in");
    document.getElementById('signinButton').setAttribute('style', 'display: none');
  } else {
    // Update the app to reflect a signed out user
    // Possible error values:
    //   "user_signed_out" - User is signed-out
    //   "access_denied" - User denied access to your app
    //   "immediate_failed" - Could not automatically log in the user
    console.log('Sign-in state: ' + authResult['error']);
  }
}
  </script>
  <title>GooglePlus Test</title>
  </head>
  <body>

<span id="signinButton">
  <span
    class="g-signin"
    data-callback="signinCallback"
    data-clientid="my_client_id.apps.googleusercontent.com"
    data-cookiepolicy="none"
    data-requestvisibleactions="http://schema.org/AddAction"
    data-scope="https://www.googleapis.com/auth/plus.login">
  </span>
</span>

  </body>
</html>

What am I doing wrong? Is it caused by opening it directly from disk? If so, why?

Thanks.

EDIT 1: When running off of a web server, the page seems to work fine, the logon dialog is being displayed. Can anyone shed a light on why this happens?

I have replicated your code and works fine, all I had to do was obviously change the sample clientid to fit mine, have you done the same? I suppose yes but never knows...

I do not run the page from a web server, I'm opening it directly from disk

I´m not an expert but it doesn't work, you have to serve it, maybe with xampp...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM