Google登录API后如何获取用户信息-JS库

时间:2020-06-19 16:09:11

标签: google-api google-oauth

我想在用户身份验证后获取他们的信息。

假设我有一个非常简单的网页,如下所示:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Get User Info</title>
  <meta name="google-signin-client_id" content="96831867432-33duead4oka3e0mbr19qnj41ecvv2h6b.apps.googleusercontent.com">
  <meta name="google-signin-scope" content="https://www.googleapis.com/auth/userinfo.profile">
</head>
<body>

<!-- The Sign-in button. This will run `getUserInfo()` on success. -->
<p class="g-signin2" data-onsuccess="getUserInfo"></p>

<script>
  function getUserInfo() {
    // we have a signed in gapi.client here
    console.log("please help")
  }
</script>

<script src="https://apis.google.com/js/client:platform.js"></script>

</body>
</html>

如何获取访问令牌,以便可以进行https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=youraccess_token或以某种方式使用gapi.client?

0 个答案:

没有答案