我很长一段时间都面临着一个问题,我无法找到解决方案 .
我想将Google登录集成到我的网站,当我登录时,我在网页上输入了't get a respond through the JavaScript that' . 我按照this article但我无法解决此问题 .
<head>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="THIS_IS_MY_ID.apps.googleusercontent.com">
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function onSignIn(googleUser) {
console.log("Signed in!");
}
</script>
</body>
当我使用Google登录时,显示的功能(onSignIn)不会运行 . 有人可以帮忙吗?
EDIT:
似乎在一个在线主机上这个脚本运行良好,所以我想我会保持这种方式,因为无论如何网站将被托管 .
1 回答
您的代码(具有有效的客户端ID)的小提琴工作 - jsFiddle - 但是当您单击它时会报告redirect_uri_mismatch .
所以你需要去:
https://console.developers.google.com/apis/credentials/consent
并配置您的项目oAuth设置 .
如果您在localhost上进行开发,请编辑主机文件并添加该行
到它,然后将Google Developers Console上的“主页网址”设置为
同样 .
因此,当您在浏览器中加载localhost.com时,它会解析为您的主机,并且.com会保持oAuth有效的主机名要求 .