启动谷歌&x2B;在JavaScript不工作的情况下登录流
我正在关注当前的趋势,出于某种原因,当我点击谷歌登录按钮时,似乎什么都没有发生,我也不完全确定为什么。代码如下:启动谷歌&x2B;在JavaScript不工作的情况下登录流,javascript,google-login,google-plus-signin,Javascript,Google Login,Google Plus Signin,我正在关注当前的趋势,出于某种原因,当我点击谷歌登录按钮时,似乎什么都没有发生,我也不完全确定为什么。代码如下: <html> <head> <title></title> <script src="https://apis.google.com/js/client:platform.js" async defer></script> </head> <body> <
<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>
/*当API完成加载时执行*/
函数render()
{
//其他参数包括回调,其余参数将
//来自页面级配置。
var附加参数={
“回调”:signinCallback
};
//将单击侦听器附加到按钮以触发流。
var signinButton=document.getElementById('signinButton');
signinButton.addEventListener('click',function(){
gapi.auth.signIn(additionalParams);//将使用页面级配置
});
}
函数signinCallback(authResult)
{
如果(authResult['status']['signed_in']){
//更新应用程序以反映已登录的用户
//现在用户已获得授权,请隐藏“登录”按钮,例如:
document.getElementById('signinButton').setAttribute('style','display:none');
}否则{
//更新应用程序以反映已注销的用户
//可能的错误值:
//“用户已注销”-用户已注销
//“拒绝访问”-用户拒绝访问您的应用
//“立即\u失败”-无法自动登录用户
log('登录状态:'+authResult['error']);
}
}
使用谷歌登录
知道我哪里出错了吗?看起来像是教程中的错误。在HTML5中,使用
src
属性在脚本标记中添加Javascript。您需要将代码移动到单独的脚本标记中
<script type="text/javascript">
// your code here
</script>
//你的代码在这里
请参见此处-您正在加载
platform.js
两次。尝试删除第一个。另外,尝试在render
函数中添加console.log
,以查看是否实际调用了它。取消了对platform.js文件的第一次调用,并使用了console.log,但什么也没有发生。我想在这里,由于某种原因,js没有被称为感谢你这么多的帮助,我真的是为没有找到问题而死!谢谢!