2
我正在使用谷歌登錄API獲取用戶信息。 我的Java腳本代碼是:Google+登錄自定義按鈕並致電
<script src="https://apis.google.com/js/client:plusone.js?onload=signinCallback"></script>
<script type="text/javascript">
var email = "";
var Id = "";
function signinCallback(authResult) {
if (authResult['status']['signed_in'] && authResult['status']['method'] == 'PROMPT') {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style',
'display: none');
gapi.client.load('plus', 'v1', function() {
var request = gapi.client.plus.people.get({
'userId' : 'me'
});
request.execute(function(resp) {
if (resp['emails']) {
for (var i = 0; i < resp['emails'].length; i++) {
if (resp['emails'][i]['type'] == 'account') {
email = resp['emails'][i]['value'];
}
}
}
Id = resp.id;
});
});
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
</script>
而我的HTML代碼:
<span id="signinButton"> <span class="g-signin" data-callback="signinCallback" data- clientid="****************************.apps.googleusercontent.com"
data-cookiepolicy="single_host_origin" data-scope="https://www.googleapis.com/auth/userinfo.email"> </span>
我的問題是它需要很長的時間來加載在按鈕谷歌的標誌,所以我想改變自定義按鈕 我想要解決這個問題。 謝謝..
如果在signincallback條件下使用authResult ['status'] ['method'] =='PROMPT',自動觸發問題就解決了。 – nmkkannan 2014-10-31 06:04:20