Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to implement Google Sign-In for a website, but the button is not appearing

I'm trying to implement the standard Google Sign-In option on a website, as they suggest here: https://developers.google.com/identity/sign-in/web/.

As a beginning, I thought I'd just follow the basic instructions (https://developers.google.com/identity/sign-in/web/devconsole-project) and I'm using nothing more than their sample code:

<html lang="en">
  <head>
    <meta name="google-signin-scope" content="profile email">
    <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script>
  </head>
  <body>
    <div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
    <script>
      function onSignIn(googleUser) {
        // Useful data for your client-side scripts:
        var profile = googleUser.getBasicProfile();
        console.log("ID: " + profile.getId()); // Don't send this directly to your server!
        console.log("Name: " + profile.getName());
        console.log("Image URL: " + profile.getImageUrl());
        console.log("Email: " + profile.getEmail());

        // The ID token you need to pass to your backend:
        var id_token = googleUser.getAuthResponse().id_token;
        console.log("ID Token: " + id_token);
      };
    </script>
  </body>
</html>

(obviously with the client id replaced by the one generated from their developer console for my site). I entered the site IP address as a valid JavaScript origin when creating the Client ID, as described. However, the login button doesn't even appear.

I feel like an idiot, because I'm sure there's some obvious step that I'm missing, but I just haven't been able to figure it out. Any recommendations?

like image 563
Grey Avatar asked Jul 03 '15 19:07

Grey


People also ask

How do I get a Google sign in button?

To create a Google Sign-In button with custom settings, add an element to contain the sign-in button to your sign-in page, write a function that calls signin2. render() with your style and scope settings, and include the https://apis.google.com/js/platform.js script with the query string onload=YOUR_RENDER_FUNCTION .

How do I use Google button?

On your device, touch and hold the Home button or say "Hey Google." If the Google Assistant is off, you'll be asked to turn it on. Ask a question or say a command.

Is login with Google free?

Google Sign-in is a free service.


1 Answers

Might be too late to respond, but here is the solution.

Remove "async defer" from loading platorm.js.

like image 53
Shirish Gone Avatar answered Oct 01 '22 01:10

Shirish Gone