10

我一直在按照本教程尝试这个简单的谷歌登录:

代码非常简单,我完全按照这些教程中给出的相同步骤进行操作,但最终出现以下错误。


400. That’s an error.

Error: invalid_request

Storagerelay URI is not allowed for 'NATIVE' client type

'NATIVE' 不允许使用 Storagerelay URI

在我的凭据中,我的配置如下:

凭据配置

我的代码如下:

<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中抛出这些答案,但现在很幸运。

  1. Google OAuth 2 授权 - 错误:redirect_uri_mismatch
  2. 谷歌登录不工作

我的基本想法是为我的网络应用程序与谷歌集成登录,如本视频所述,让我知道这种方法是否好。

4

2 回答 2

7

这是因为您没有 Web 服务器的客户端 ID。在进行设置以获取客户 ID 时,您没有正确选择它。(您为“其他”选择了它)。我遇到了完全相同的问题,但后来我更改了 Web 服务器的客户端 ID,现在它运行良好。

于 2018-12-24T19:21:24.350 回答
1

我知道这已经得到解答,但就我而言,在使用 Electron 和 React 开发桌面应用程序时,我已将 OAuth2 凭据类型设置为“桌面”。将其更改为“Web 应用程序”为我解决了这个问题。

于 2021-01-27T20:32:15.547 回答