我正在尝试集成Google的登录。在本地python SimpleHTTPServer上运行一个基本示例可以正常工作,除了getBasicProfile()方法返回一个空对象的事实。它不显示名称,电子邮件,imageUrl,ID ...
片段:
<html>
<head>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="123456789_fake_987654321.apps.googleusercontent.com">
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<a href="#" onclick="signOut();">Sign out</a>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log(profile.getId());
console.log(profile.getName());
console.log(profile.getImageUrl());
console.log(profile.getEmail());
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
</body>
</html>
该api会打开一个新窗口,允许我输入我的凭据并以没有问题的方式登录和注销。仅定义的googleUser对象会继续返回空属性。
有任何想法吗?
发现python SimpleHTTPServer使用的是端口8000。
我必须将具有端口号的http:// localhost:8000而不是http:// localhost添加到受限制的JavaScript Origins中,并重定向我的Google客户端ID的URI。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句