现在我正在使用auth2.attachClickHandler(element, {}, onSuccess, onError);
。它可以工作,但如果我已经登录,对话框会立即打开和关闭,这相当丑陋。有没有办法绕过这个using listeners?
我玩了一些示例,但我不确定是否只需要听取当前用户的更改,而且我对googleUser
的检查似乎有风险。
auth2 = gapi.auth2.init({client_id: 'xxxxx'});
auth2.currentUser.listen(function (user) {
googleUser = user;
if (typeof(googleUser.getBasicProfile()) !== 'undefined')
document.getElementById('signupAsGoogle').addEventHandler('click', popuplateForm);
else
auth2.attachClickHandler(document.getElementById('signupAsGoogle'), {}, onSuccess, onError);
有更好的方法吗?感谢
答案 0 :(得分:0)
以下是我为解决同样问题所做的工作!
auth2 = gapi.auth2.init({
clientid: '${clientId}',
cookiepolicy: '${cookie_policy}',
});
auth2.currentUser.listen(function (googleUser) {
if (googleUser.isSignedIn()) {
// do your login(googleUser) function
} else {
auth2.attachClickHandler("your button", {},
function (googleUser) {
// do your login(googleUser) function
}, function (error) {
});
}
});