我按照以下教程尝试了这个简单的Google登录:
代码非常简单,我完全遵循这些教程中给出的相同步骤,但最终出现了以下错误。
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');
});
}
每次点击&#34;使用Google登录&#34;按钮,新弹出窗口打开,400错误抛出。
我也试过在stackoverflow中增加这些答案,但现在好运。
我的基本想法是将登录与google整合到我的网络应用中,如video中所述,让我知道这种方法是否合适。
答案 0 :(得分:2)
这是因为您没有Web服务器的客户端ID。设置获取客户ID时,您没有正确选择它。(您选择了“其他”)。 我面临着完全相同的问题,但是后来我更改了Web服务器的客户端ID,现在它可以正常工作了。
答案 1 :(得分:0)
我知道这已经得到解答,但就我而言,在使用 Electron 和 React 开发桌面应用程序时,我将 OAuth2 凭据类型设置为“桌面”。将其更改为“Web 应用程序”为我解决了这个问题。