我一直在按照本教程尝试这个简单的谷歌登录:
- https://developers.google.com/identity/sign-in/web/
- http://www.codexworld.com/login-with-google-account-using-javascript/
代码非常简单,我完全按照这些教程中给出的相同步骤进行操作,但最终出现以下错误。
400. That’s an error.
Error: invalid_request
Storagerelay URI is not allowed for 'NATIVE' client type
在我的凭据中,我的配置如下:
我的代码如下:
<meta name="google-signin-client_id" content="377345478968-2opk94iompa38gja0stu1vi821lr3rt0.apps.googleusercontent.com">
<script src="https://apis.google.com/js/client:platform.js?onload=renderButton" async defer></script>
<div id="gSignIn"></div>
function onSuccess(googleUser) {
var profile = googleUser.getBasicProfile();
gapi.client.load('plus', 'v2', function () {
var request = gapi.client.plus.people.get({
'userId': 'me'
});
//Display the user details
request.execute(function (resp) {
console.log(resp);
});
});
}
function onFailure(error) {
alert(error);
}
function renderButton() {
gapi.signin2.render('gSignIn', {
'scope': 'profile email',
'width': 240,
'height': 50,
'longtitle': true,
'theme': 'dark',
'onsuccess': onSuccess,
'onfailure': onFailure
});
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
$('.userContent').html('');
$('#gSignIn').slideDown('slow');
});
}
每次单击“使用 Google 登录”按钮时,都会打开新的弹出窗口并抛出 400 错误。
我也尝试过在stackoverflow中抛出这些答案,但现在很幸运。
我的基本想法是为我的网络应用程序与谷歌集成登录,如本视频所述,让我知道这种方法是否好。