使用 JavaScript 启动 Google+ 登录流程不起作用
Initiating the Google+ Sign-In flow with JavaScript not working
我正在按照当前的教程进行操作,出于某种原因,每当我单击"使用 Google 登录"按钮时,似乎什么都没有发生,我不完全确定为什么。这是代码:
<html>
<head>
<title></title>
<script src="https://apis.google.com/js/client:platform.js" async defer></script>
</head>
<body>
<meta name="google-signin-clientid" content="782332402251-os0n348u3v5vaq5kff87f5pc65ib6i19.apps.googleusercontent.com" />
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/plus.login" />
<meta name="google-signin-requestvisibleactions" content="http://schema.org/AddAction" />
<meta name="google-signin-cookiepolicy" content="single_host_origin" />
<script src="https://apis.google.com/js/client:platform.js?onload=render" async defer>
/* Executed when the APIs finish loading */
function render()
{
// Additional params including the callback, the rest of the params will
// come from the page-level configuration.
var additionalParams = {
'callback': signinCallback
};
// Attach a click listener to a button to trigger the flow.
var signinButton = document.getElementById('signinButton');
signinButton.addEventListener('click', function() {
gapi.auth.signIn(additionalParams); // Will use page level configuration
});
}
function signinCallback(authResult)
{
if (authResult['status']['signed_in']) {
// 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');
} 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>
<button id="signinButton">Sign in with Google</button>
</body>
</html>
知道我哪里出错了吗?
看起来教程中的一个错误。在具有 src
属性的脚本标记中嵌入 Javascript 在 HTML5 中无效。您需要将代码移动到单独的脚本标记中。
<script type="text/javascript">
// your code here
</script>
看这里 - http://jsfiddle.net/7umb41z2/
相关文章:
- 我的点击登录在网页上不起作用
- 意思是.js - 登录后重定向用户 - 在本地工作,但在部署时不起作用
- 科尔多瓦脸书登录FB.api调用不起作用
- PHP登录不起作用
- 登录后PHP登录脚本重定向不起作用
- 如果用户登录不起作用,则运行脚本
- 会话在登录页不起作用
- JSP-Javascript-JSP 登录流程不起作用
- $.mobile.changePage() 登录后不起作用
- Facebook 登录在 CN1 JavaScript 端口中不起作用
- Phonegap/Cordova facebook 登录在已经连接时不起作用
- Facebook 登录重定向 PHP/Javascript 不起作用
- HTML 登录不起作用
- $location.path() 在 facebook 登录后不起作用
- 谷歌加登录按钮已呈现,但不起作用
- 使用 JavaScript 启动 Google+ 登录流程不起作用
- 使用 Angular JS 登录,$http请求不起作用
- Facebook自动登录JS在控制台中工作,但在GM脚本中不起作用
- FB.登录响应会话不起作用
- 导航栏折叠在登录模板上不起作用