我已经在网站中使用 javascript sdk 使用 google plus 登录。它在两天前工作。但现在它不起作用,因为 gapi.client.load('oauth2', 'v2', function()); 未加载即不工作。请帮忙。
下面是我的代码:
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
gapi.signin.render('customBtn', {
'callback': 'signinCallback',
'clientid': '<client ID>',
'cookiepolicy': 'single_host_origin',
'requestvisibleactions': 'http://schemas.google.com/AddActivity',
'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com /auth/userinfo.email'
});
function signinCallback(authResult) {
if (authResult['access_token']) {
gapi.auth.setToken(authResult);
getEmail();
} else if (authResult['error']) {
alert('Please try again');
// alert('There was an error: ' + authResult['error']);
}
}
function getEmail(){
// Load the oauth2 libraries to enable the userinfo methods.
try
{
gapi.client.load('oauth2', 'v2', function() {
var request_mail = gapi.client.oauth2.userinfo.get();
request_mail.execute(getEmailCallback);
});
}
catch(err)
{
alert( "onLoadCallback error: " + err.message );
}
}
function getEmailCallback(obj){
if (obj['email']) {
$('login:email').value = obj['email'];
checkout.setMethod();
}
}