【问题标题】:Google People API Returning 'The request is missing a valid API key.'Google People API 返回“请求缺少有效的 API 密钥。”
【发布时间】:2018-07-05 02:49:14
【问题描述】:

我没有对 Chrome 扩展程序中的 Google 表格集成进行任何代码更改(仅在我们公司内部使用)。今天,我收到“403”错误消息“请求缺少有效的 API 密钥。”

我没有使用 API 密钥,也从未使用过 - 只是一个客户端 ID。多年来,这一直很棒,直到今天或昨天。

我的作用域是https://www.googleapis.com/auth/spreadsheetshttps://www.googleapis.com/auth/userinfo.profile

有什么想法吗?这里有什么我不知道的变化吗?我确实看到了这个:https://github.com/zquestz/omniauth-google-oauth2/issues/106,但时间框架与我所看到的不符。

【问题讨论】:

    标签: google-sheets-api google-people-api google-apps-activity


    【解决方案1】:

    我遇到了同样的问题,解决方法是手动设置 OAuth2 令牌:

    gapi.auth.setToken({access_token: oauthToken});
    

    对于上下文,这是我的 background.js 中的身份验证和初始化流程:

    var oauthToken;
    
    chrome.identity.getAuthToken(
      {
        'interactive': true,
        'scopes': <scopes>,
      },
      function(token) {
        oauthToken = token;
    
        // load Google client APIs
        window.gapi_onload = authGapi;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
          if ((request.readyState !== 4) || (request.status !== 200)) {
                return;
              }
          eval(request.responseText);
        };
        request.open('GET', 'https://apis.google.com/js/client.js');
        request.send();
        }
    );
    
    var authGapi = function() {
      gapi.auth.authorize({
            immediate: true,
            client_id: <clientId>,
            scope: <scopes>,
      },
      function(response) {
        gapi.client.init({
          discoveryDocs: [
            'https://sheets.googleapis.com/$discovery/rest?version=v4',
          ]
        }).then(function() {
          gapi.auth.setToken({access_token: oauthToken});
          });
      });
    }
    

    【讨论】:

    • 这并不能真正回答问题。如果您有其他问题,可以点击 进行提问。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
    • @TomAranda - 我相信这确实回答了这个问题:)
    • 确实有很大改进。
    猜你喜欢
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多