刷新 OAuth2 令牌时出错 @ Google_CalendarServices (php)

Error refreshing the OAuth2 token @ Google_CalendarServices (php)

我知道有很多类似的问题,其中 'invalid_grant' 是我们从 google api 得到的唯一 'answer',但它们都是旧的,或者正在讨论获取相同消息的不同方式。

奇怪的是,这个 'thing' 仅在 2 天前停止工作。在我们的 CRM 中,我们将会议预订到与我们的 Google 帐户关联的 Google 日历中。现在在过去的两天里我们遇到了以前从未发生过的问题。

申请失败是这样的:

Fatal error:  Uncaught exception 'Google_AuthException' with message 'Error refreshing the OAuth2 token, message: '{"error" : "invalid_grant";}

Stack trace:

#0 /path/to/plugins/google-api-php-client/src/auth/Google_OAuth2.php(240): Google_OAuth2->refreshTokenRequest(Array)
#1 /path/to/plugins/google-api-php-client/src/auth/Google_OAuth2.php(217): Google_OAuth2->refreshToken('1/ourtoken...')
#2 /path/to/plugins/google-api-php-client/src/service/Google_ServiceResource.php(167): Google_OAuth2->sign(Object(Google_HttpRequest))
#3 /path/to/plugins/google-api-php-client/src/contrib/Google_CalendarService.php(494): Google_ServiceResource->__call('insert', Array)

这是实际的 http 答案:

Google_HttpRequest Object
(
    [batchHeaders:Google_HttpRequest:private] => Array
        (
            [Content-Type] => application/http
            [Content-Transfer-Encoding] => binary
            [MIME-Version] => 1.0
            [Content-Length] => 
        )

    [url:protected] => https://accounts.google.com/o/oauth2/token
    [requestMethod:protected] => POST
    [requestHeaders:protected] => Array
        (
            [content-type] => application/x-www-form-urlencoded
            [content-length] => 196
        )

    [postBody:protected] => client_id=111111111.apps.googleusercontent.com&client_secret=secretSECTRETsecretSECRET&refresh_token=1%2FveryLONGtokenSTRINGhafbuaADDFR&grant_type=refresh_token
    [userAgent:protected] => Google Calendar PHP Starter Application google-api-php-client/0.6.0
    [responseHttpCode:protected] => 400
    [responseHeaders:protected] => Array
        (
            [content-type] => application/json; charset=utf-8
            [cache-control] => no-cache, no-store, max-age=0, must-revalidate
            [pragma] => no-cache
            [expires] => Mon, 01 Jan 1990 00:00:00 GMT
            [date] => Thu, 10 Nov 2016 01:05:15 GMT
            [x-content-type-options] => nosniff
            [x-frame-options] => SAMEORIGIN
            [x-xss-protection] => 1; mode=block
            [server] => GSE
            [alt-svc] => quic=":443"; ma=2592000; v="36,35,34"
            [accept-ranges] => none
            [vary] => Accept-Encoding
            [transfer-encoding] => chunked
        )

    [responseBody:protected] => {
  "error" : "invalid_grant"
}
    [accessKey] => 
)

是的,我们使用的是旧版本而不是新版本。是的,账户是活的,我们试图插入的日历是存在的。没有权限或密码 changed/reset。我们尝试了所有的日历——一点都不成功。我也尝试了一些小的 changes/hacks 我在这里发现像不使用开发者密钥,将访问类型设置为离线,同步服务器时间等等...

实际上,在它坏掉之前我们什么也没做。所以有一个问题:Google 是否更改了 behaviour/code 中的某些内容?还是我们错过了什么(比如 deprecated/deleted 函数)?

编辑 #1

我的一所大学确实改变了一些东西。 (更多内容在编辑部分末尾)

所以我们有一个 'main' google 帐户,有开发人员密钥和客户端 ID 以及所有内容 -> 这个帐户还有 1 个日历。

我们 co-workers 还有多个其他 google 帐户。我们有从主日历到他们的日历和 vice-versa 的赠款。在我们的 CMS 中,我们尝试向 co-workers 日历之一添加一个事件(因此在 Google_CalendarService 上插入)。

所以我们 co-workers 中的一个人辞掉了工作,我的大学更改了 HIS 密码。并取消了赠款。好吧,它发生在星期一 16:00 和星期二早上,我们遇到了第一个错误。这个 google 帐户的更改会影响所有其他帐户的行为吗?主日历帐户的行为???

-- 编辑 #1 结束

如果有人遇到类似的情况并设法解决了,请提供一些建议。谢谢!

11/17/2016 更新:

我们确实发现了导致某些令牌被清除的问题。我们正在努力确保它不会再次发生。很遗憾,无法恢复已删除的令牌,您的用户将不得不重新授权。


我们(Google 身份团队)正在调查此问题,因为其他一些开发人员也已与我们联系。为了加快调试速度, 你能通过我的 G+ 个人资料向我发送即时消息吗,这样我就可以获取一些信息并进行调查。

"did Google changed something in the behaviour/code or something? " 答案是否定的,没有有意更改。

大家好消息(谁在乎)!

经过无休止的挖掘和尝试&失败,我发现 google 实际上已经阻止了我们的旧访问令牌。也许是我们这边的密码更改和授权删除,也许是前同事试图撤销或重置某些东西,不确定。但是令牌不再有效。

在 Oauth2 游乐场进行一些小挑战后,我已经建立了与我们的 API 凭据的连接,并获得了新的连接首选项(新的访问令牌和新的刷新令牌)

特别感谢并特别感谢@DaImTo 指出,可能是 inactive/old 标记导致了这个问题。

@Google: 请添加有意义的错误信息和错误描述,如果 2-3 天解决 'minor' 但像这样的关键问题,损失几分钟到几小时会更酷!

我希望这篇post对以后的人有所帮助。和平!

我制作的一个旧应用程序也遇到了同样的问题。通过重新生成客户端密码和开发人员密钥只是为了安全,应用程序再次运行,您将尝试的任何其他操作都会失败。可惜浪费了一个上午。