我的头部代码如下:
<meta name="google-signin-clientid" content="XXXXXXX.apps.googleusercontent.com" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
<meta name="google-signin-approvalprompt" content="auto" />
<meta name="google-signin-callback" content="signinCallback" />
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/games" />
这是我的按钮代码:
<span id="signinButton"><span class="g-signin"></span></span>
以下是JavaScript代码:
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
console.log('Signed In');
} else {
console.log('Sign-in state: ' + authResult['error']);
}
}
(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);
})();
当我点击登录按钮时,会弹出一个对话框进行身份验证,然后控制台会打印以下内容:
- 登录状态:已登录,时间为 Wed May 21 2014 17:31:05 GMT-0700 (PDT)
- 登录状态:用户已注销,时间为 Wed May 21 2014 17:31:06 GMT-0700 (PDT)
- 登录状态:用户已注销,时间为 Wed May 21 2014 17:31:06 GMT-0700 (PDT)
- 登录状态:用户已注销,时间为 Wed May 21 2014 17:31:08 GMT-0700 (PDT)