2

我正在尝试使用谷歌一键登录来获取个人资料信息,我正在获取 clientId 和凭据而不是用户个人资料,我也使用了其他 gapi 方法,但我无法得到它任何人都可以建议如何提取

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <script src="https://accounts.google.com/gsi/client" async defer></script>
    <script src="https://apis.google.com/js/client.js?onload=authorize"></script>
    <script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-firestore.js"></script>
  </head>
  <body>
    <div
      id="g_id_onload"
      data-client_id="xxxxxx"
      data-callback="handleCredentialResponse"
    ></div>
    <script>
      function handleCredentialResponse(response) {
        console.log(response);
        auth2 = gapi.auth2.init({
          client_id: "xxxxxx",
          scope:
            "email profile https://www.googleapis.com/auth/plus.business.manage",
          prompt: "none",
        });
        auth2.signIn().then(function () {
          console.log(auth2.currentUser);
        });
        auth2
          .grantOfflineAccess({
            scope:
              "email profile https://www.googleapis.com/auth/plus.business.manage",
          })
          .then(async function (resp) {
            var auth_code = resp.code;
            // here i am getting the authorization code 
          });
      }
    </script>
  </body>
</html>
4

0 回答 0