我正在使用google日历api将事件写入组织的日历,但我想不出如何刷新访问令牌,以便我的程序一次可以使用日历超过一个小时。
要重新创建错误,请执行以下操作:
从https://developers.google.com/oauthplayground
H 220
attempt>G 221
attempt>刷新您的e 118访问令牌E 219E 219。问题
谷歌的OAuth游乐场接入令牌在3600秒(1小时)后到期。我可以使用google的临时客户凭证刷新访问令牌,但是当我尝试提出请求时(无论是从操场本身还是从邮递员),都会遇到以下错误消息:
{
"error_description": "Unauthorized",
"error": "unauthorized_client"
}我已经验证了oauth操场被列为云控制台中我的客户端的有效重定向uri。我还将我的POST请求与谷歌在刷新访问令牌时发送的请求和占位符凭证进行了比较,以确保我正在发送所有必要的params。
REQUESTS/RESPONSES
使用的默认客户凭据在Oauth游乐场上发布请求
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-length: 223
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
client_secret=************&grant_type=refresh_token&refresh_token=1%2F%2F04qg5N0zhIRbPCgYIARAAGAQSNwF-L9IrTEZny7y_4wpbjLUh7ImtWRu473AQeTG3NG49ogQVzDZJe99BnS1TwFjwX7S2mNbLOYQ&client_id=407408718192.apps.googleusercontent.com在谷歌oauth操场发出上述请求时的响应
HTTP/1.1 200 OK
Content-length: 385
X-xss-protection: 0
X-content-type-options: nosniff
Transfer-encoding: chunked
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Vary: Origin, X-Origin, Referer
Server: scaffolding on HTTPServer2
-content-encoding: gzip
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Wed, 31 Aug 2022 22:13:53 GMT
X-frame-options: SAMEORIGIN
Alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Content-type: application/json; charset=utf-8
{
"access_token": "ya29.a0AVA9y1sTkPpmJIHvIBNODwdXr36hzumPEmoJGFBB1y29SZVwiE_QBy7RuTjDNzPkKyBOJ7RD1LBceTooeUZuNl-wN5dkyqsjFF5ynMkcShwG_yADXazPUFXngsSGuW_WRuVR01s9FOnv2N5gzkPldvQEtLaZaCgYKATASAQASFQE65dr8ZDuFe5BQyBG8ostdxK5ObQ0163",
"scope": "https://www.googleapis.com/auth/calendar.events https://www.googleapis.com/auth/calendar",
"expires_in": 3599,
"token_type": "Bearer"
}使用我的客户凭证向谷歌的Oauth操场发布请求
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-length: 279
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
client_secret=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&grant_type=refresh_token&refresh_token=1%2F%2F04qg5N0zhIRbPCgYIARAAGAQSNwF-L9IrTEZny7y_4wpbjLUh7ImtWRu473AQeTG3NG49ogQVzDZJe99BnS1TwFjwX7S2mNbLOYQ&client_id=804898855072-r91v64ojblf83if1pe9f8vr4mumubecc.apps.googleusercontent.com在谷歌oauth操场发出上述请求时的响应
HTTP/1.1 401 Unauthorized
Content-length: 75
X-xss-protection: 0
X-content-type-options: nosniff
Transfer-encoding: chunked
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Vary: Origin, X-Origin, Referer
Server: scaffolding on HTTPServer2
-content-encoding: gzip
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Wed, 31 Aug 2022 22:16:15 GMT
X-frame-options: SAMEORIGIN
Alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Content-type: application/json; charset=utf-8
{
"error_description": "Unauthorized",
"error": "unauthorized_client"
}如有任何指导,将不胜感激。谷歌真的需要一些更好的文档!
发布于 2022-09-01 10:26:32
unauthorized_client
通常意味着您使用的客户端id和客户端机密与刷新令牌不是用来创建它的客户端id和客户端机密。
您不应该使用操场来创建令牌。你应该在你的应用程序中创建它们,在你的应用程序中刷新它们。
记住,不能使用客户端语言刷新令牌。我不是一个reactJs,所以如果这是在运行客户端,这也可能是您的错误的原因。使用服务器端语言。
https://stackoverflow.com/questions/73562462
复制相似问题