[英]Web app Google sign-in
我正在将google登录功能集成到我的网络应用程序中。 我遵循了这里的指示。 但是我无法从登录中获取任何用户信息。 登录按钮可以正常工作。
<meta name="google-signin-client_id" content="3*****-c*******************.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<div class="g-signin2 googleSignIn" data-onsuccess="onSignIn"></div>
我使用以下javascript函数:
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
email=profile.getEmail();
}
}
该函数导致错误:未定义auth2。 如果我在函数之前使用window.onLoadCallback = function()
,那么它不会给出错误,但日志中也不会给出任何信息。 如果我只使用这个:
function onSignIn(googleUser) {
var id_token = googleUser.getAuthResponse().id_token;
console.log("done");
}
再次,我没有收到任何错误,但控制台日志中也没有任何内容。
将此代码放在(auth2.isSignedIn.get())之前。 尝试运行它。
gapi.load('auth2', function () {
auth2 = gapi.auth2.init();
// Sign the user in, and then retrieve their ID.
auth2.signIn().then(function () {
console.log(auth2.currentUser.get().getId());
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.