使用 google 签名时出现错误 400
getting error 400 on signing with google
我想在我的网站上创建 google 登录,使用的代码来自 google 开发者网站 here,我使用 php 进行编码,我的代码是
<!DOCTYPE html>
<html>
<head>
<title>Google Login</title>
<meta name="google-signin-client_id" content="9252517****-o9350mh2vrp58maddlv0aeitkd0c****.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
function onSignIn(googleUser)
{
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
function signOut()
{
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function ()
{
console.log('User signed out.');
});
}
</script>
</head>
<body>
<div align="center" margin-top="100px">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<a href="#" onclick="signOut();">Sign out</a>
</div>
</body>
</html>
登录后我收到类似这样的错误错误:redirect_uri_mismatch
请求中的 JavaScript 来源:http://localhost 与注册的 JavaScript 来源不匹配。
您可以检查错误 here.
请帮我解决这个问题。
经过长时间的搜索,我找到了神奇地解决我的问题的解决方案。
如错误 http://localhost did not match a registered JavaScript origin I set http://localhost 所示,而不是我在 console.developer 站点中的重定向 url 中的完整路径,它有效。
我想在我的网站上创建 google 登录,使用的代码来自 google 开发者网站 here,我使用 php 进行编码,我的代码是
<!DOCTYPE html>
<html>
<head>
<title>Google Login</title>
<meta name="google-signin-client_id" content="9252517****-o9350mh2vrp58maddlv0aeitkd0c****.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
function onSignIn(googleUser)
{
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
function signOut()
{
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function ()
{
console.log('User signed out.');
});
}
</script>
</head>
<body>
<div align="center" margin-top="100px">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<a href="#" onclick="signOut();">Sign out</a>
</div>
</body>
</html>
登录后我收到类似这样的错误错误:redirect_uri_mismatch 请求中的 JavaScript 来源:http://localhost 与注册的 JavaScript 来源不匹配。 您可以检查错误 here.
请帮我解决这个问题。
经过长时间的搜索,我找到了神奇地解决我的问题的解决方案。 如错误 http://localhost did not match a registered JavaScript origin I set http://localhost 所示,而不是我在 console.developer 站点中的重定向 url 中的完整路径,它有效。