Gre*_*rey 8 javascript google-signin
我正在尝试在网站上实施标准的 Google 登录选项,正如他们在此处建议的那样:https : //developers.google.com/identity/sign-in/web/。
一开始,我想我只需要遵循基本说明(https://developers.google.com/identity/sign-in/web/devconsole-project),我只使用他们的示例代码:
<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>
Run Code Online (Sandbox Code Playgroud)
(显然,客户端 ID 被他们的开发人员控制台为我的站点生成的 ID 所取代)。如上所述,我在创建客户端 ID 时输入了站点 IP 地址作为有效的 JavaScript 来源。但是,登录按钮甚至没有出现。
我觉得自己像个白痴,因为我确定我遗漏了一些明显的步骤,但我一直无法弄清楚。有什么建议吗?
| 归档时间: |
|
| 查看次数: |
6104 次 |
| 最近记录: |