【问题标题】:Uncaught exception 'Google_Service_Exception' with message带有消息的未捕获异常“Google_Service_Exception”
【发布时间】:2017-02-14 13:17:48
【问题描述】:

我正在使用“谷歌电子表格 API”从谷歌驱动器中获取数据。 有时它会显示以下错误。但是一旦我清除会话并再次重新加载页面,它就会运行良好。

'致命错误:'

Uncaughtexception'Google_Service_Exception'withmessage
{
    "error":
    {
        "code":
        401, "message":
            "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors":
            [{
                "message":
                    "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "domain":
                    "global", "reason":
                    "unauthorized"
        }], "status":
        "UNAUTHENTICATED"
    }
}

【问题讨论】:

    标签: google-drive-api google-spreadsheet-api


    【解决方案1】:

    您可能需要查看有关 Verify the integrity of the ID token 的文档:

    如果您将 Google 登录用于与后端服务器通信的应用或网站,您可能需要识别服务器上当前登录的用户。要安全地执行此操作,请在用户成功登录后,使用 HTTPS 将用户的 ID 令牌发送到您的服务器。然后,在服务器上,验证 ID 令牌的完整性,并从 ID 令牌的 sub 声明中检索用户的 ID。您可以使用以这种方式传输的用户 ID 来安全地识别后端当前登录的用户。

    在相关的 SO post 中,他们显示了一个 document,它最好地解释了如何正确处理 401:Invalid Credentials 问题。

    注意:

    您可以使用适用于您平台的 Google API 客户端库,或者调用我们的 tokeninfo 验证端点,而不是编写自己的代码来执行这些验证步骤。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-08
      • 2013-02-01
      • 2016-02-27
      • 1970-01-01
      • 2012-07-08
      • 2012-12-03
      • 2014-11-15
      • 2014-08-09
      相关资源
      最近更新 更多