刷新OAuth2令牌@ Google_CalendarServices(php)时出错 [英] Error refreshing the OAuth2 token @ Google_CalendarServices (php)

查看:80
本文介绍了刷新OAuth2令牌@ Google_CalendarServices(php)时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多类似的问题,其中"invalid_grant"是我们从google api获得的唯一答案",但是它们都是古老的,或者讨论了获取同一条消息的不同方法.

i know there are many similar questions, where the 'invalid_grant' is the only 'answer' we got from google api, but all them are old, or discussing different ways of getting to the same message.

奇怪的是,这个东西"仅在2天前停止工作.在我们的CRM中,我们将会议预订到与我们的GoogleAccount关联的GoogleCalendars中.现在,在过去的两天里,我们遇到了以前从未发生过的问题.

The weird part is, that this 'thing' only stopped working for 2 days ago. In our CRM we book meetings into GoogleCalendars associated with our GoogleAccount. Now in the last 2 days we are experiencing problems, never happend before.

应用程序失败,如下所示:

The application fails like this:

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答案:

This is the actual http answer:


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] => 
)

是的,我们使用的是旧版本,而没有新版本.是的,该帐户是真实的,我们要插入的日历已存在.没有特权或密码被更改/重置.我们尝试了所有日历-完全没有成功.我还尝试了一些小的更改/黑客,例如不使用开发人员密钥,将访问类型设置为脱机,同步服务器时间等等.

Yes we are using an older version not anything new. Yes the account is live, the calendar into which we are trying to insert is existing. No privileges or passwords were changed/reset. We tried all our calendars - no success at all. And i tried also some minor changes/hacks I found here like not using developer key, set access type to offline, synchronizing server time and so on...

实际上,在事情破裂之前,我们对这件事没有做任何事情.因此,有一个问题:Google是否更改了行为/代码中的某些内容?还是我们错过了某些东西(例如已弃用/删除的功能)?

Actually we did nothing with the whole thing before it broke. So there is one question: did Google changed something in the behaviour/code or something? Or did we miss something (like deprecated/deleted functions)?

编辑#1

我的一所大学确实改变了某些事实. (有关详细信息,请参见编辑部分的结尾)

One of my colleges did change something in fact. (More on that at the end of edit section)

因此,我们有一个主" Google帐户,开发人员密钥和clientid以及所有内容->并且此帐户也有1个日历.

So we have one 'main' google account, wit developer key and clientid and everything -> and this account also has 1 calendar.

我们为同事提供了多个其他Google帐户.从主日历到他们的日历,我们都会提供赠款,反之亦然.在我们的CMS中,我们尝试将事件(因此在Google_CalendarService上插入)添加到其中一个同事日历中.

Than we have multiple other google accounts for our co-workers. We have grants from main calendar to their calendars and vice-versa. In our CMS we try to add an event (hence insert on Google_CalendarService) to one of the co-workers calendar.

因此我们的一位同事辞职了,我的大学更改了 HIS 密码.并删除了赠款.好吧,这发生在星期一的16:00,星期二的早晨,我们遇到了第一个错误.这个Google帐户的更改可能会影响其他所有帐户的行为吗?主日历帐户的行为????

So one of our co-workers quit the job, and my college change HIS password. And removed grants. Well it happend Monday at 16:00 and Tuesday morning we got the first error. Could this one google account's change affect the behaviour of all other, resp. the behaviour of the main calendar account???

-编辑#1结束

如果有人遇到类似问题并设法解决,请提供一些建议.谢谢!

If anyone experienced something similar like this and managed to fix, please give some advise. Thank you!

推荐答案

每个人(都在乎)的好消息!

Good news everyone (who cares at all)!

无休止的挖掘和尝试失败后,我发现Google实际上阻止了我们的旧访问令牌.可能是密码更改并从我们这边取消了授权,也许是前同事试图撤消或重置某些内容,但不确定.但是令牌不再有效.

After endless digging and try&fails, I found out that google had in fact blocked our old access token. Maybe it was the password change and grant removal from our side, maybe it was the ex-co-workers attempt to revoke or reset something, not sure. But the token was not active anymore.

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

After some small challanges with the Oauth2 Playground I've set up a connection with our API credentials, and got the new connection preferences (new access token and new refresh tokens)

特别感谢@DaImTo并大声喊着,这可能是导致此问题的无效/旧令牌.

Special thanks and a big shout out to @DaImTo for pointing out, that it's probably the inactive/old token what is causing this issue.

@Google:请添加有意义的错误消息和错误描述,这样可以减少2-3天的几分钟到几小时的时间来解决诸如此类的次要"但至关重要的问题,真是太酷了!

@Google: please add meaningful error messages and error descriptions, it will be much cooler to lose some minutes to hours as 2-3 days to solve 'minor' but critical issues like this one!

我希望这篇文章将来能对某人有所帮助.和平!

I hope this post will help someone once in the future. Peace!

这篇关于刷新OAuth2令牌@ Google_CalendarServices(php)时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆