如何在我的网站中实施Google API

时间:2017-04-02 08:08:14

标签: java

enter link description here http://www.sevenieslab.com.

如何添加Google API以允许我的用户通过我的网站中的gmail帐户注册

1 个答案:

答案 0 :(得分:1)

对于Web应用程序,您可以使用Goole Sign-In api。

此示例代码可以帮助您入门。 它将返回基本用户详细信息,如:姓名,个人资料图片等。 你可以在这里找到更多细节: https://developers.google.com/identity/

<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('Full Name: ' + profile.getName());
        console.log('Given Name: ' + profile.getGivenName());
        console.log('Family Name: ' + profile.getFamilyName());
        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>