【问题标题】:403 Forbidden Error from google API Javascript client来自谷歌 API Javascript 客户端的 403 禁止错误
【发布时间】:2017-01-19 11:45:03
【问题描述】:

我从 google API Javascript 客户端收到 403 Forbidden Error。以下是我的代码:

gapi.load('client', function () {
    console.log('gapi.client loaded.');
    var discoveryUrl = 'https://sheets.googleapis.com/$discovery/rest?version=v4';
    gapi.client.load(discoveryUrl).then(function () {
        console.log('gapi.client.sheets loaded.');
        gapi.client
            .init({
                apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
                clientId: '0000000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',
                scope: 'https://www.googleapis.com/auth/spreadsheets',
            })
            .then(function () {
                return gapi.client.sheets.spreadsheets.get({
                    spreadsheetId: spreadsheetId,
                });
            })
            .then(
                function (response) {
                    console.log(response);
                },
                function (response) {
                    console.log(response);
                },
            );
    });
});

我的应用程序在 servlet 容器中运行,并且 oauth2 在服务器端处理。如果我想添加 authToken 我该怎么做?

【问题讨论】:

  • 在我的情况下,当我尝试修改已删除的事件时出现“禁止”错误

标签: google-sheets-api google-api-js-client


【解决方案1】:

您可以在此documentation 中查看您获得403 Forbidden Error 的原因。表示服务器理解请求但拒绝授权。希望公开请求被禁止的原因的服务器可以在响应负载(如果有)中描述该原因。

如果请求中提供了身份验证凭据,服务器会认为它们不足以授予访问权限。客户端不应使用相同的凭据自动重复请求。客户端可以使用新的或不同的凭据重复请求。但是,由于与凭据无关的原因,可能会禁止请求。

如果我想添加 authToken,我该怎么做?

关注有关Authorize Requests 的文档。您可以使用OAuth 2.0 token 来识别您的应用程序。

您也可以查看这些相关主题:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 2014-11-25
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    相关资源
    最近更新 更多