gpt4 book ai didi

javascript - 在 JavaScript 不起作用的情况下启动 Google+ 登录流程

转载 作者:行者123 更新时间:2023-11-29 16:11:10 26 4
gpt4 key购买 nike

我正在关注当前的 tutorial出于某种原因,当我点击“使用 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 是 not valid在 HTML5 中。您需要将代码移动到单独的脚本标记中。

<script type="text/javascript">
// your code here
</script>

请看这里 - http://jsfiddle.net/7umb41z2/

关于javascript - 在 JavaScript 不起作用的情况下启动 Google+ 登录流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27711811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com