2017-01-20 79 views
0

儘管tokeninfo告訴我我正在使用的訪問令牌具有適當的範圍,但有些(但不是全部)Google帳戶在嘗試訪問Google Calendar API時始終如一地迴應401(請參閱curl輸出如下)。我可以使用刷新令牌成功獲取新的訪問令牌,但日曆API仍然會延續至401個。Google Calendar API 401「無效憑證」

有沒有人知道爲什麼會出現這種情況?

$ curl -v https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=[redacted] 
* Trying 216.58.195.74... 
* Connected to www.googleapis.com (216.58.195.74) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 
* Server certificate: *.googleapis.com 
* Server certificate: Google Internet Authority G2 
* Server certificate: GeoTrust Global CA 
> GET /oauth2/v3/tokeninfo?access_token=[redacted] HTTP/1.1 
> Host: www.googleapis.com 
> User-Agent: curl/7.49.1 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
< Pragma: no-cache 
< Expires: Mon, 01 Jan 1990 00:00:00 GMT 
< Date: Tue, 18 Oct 2016 22:00:45 GMT 
< Vary: X-Origin 
< Content-Type: application/json; charset=UTF-8 
< 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,33,32" 
< Accept-Ranges: none 
< Vary: Origin,Accept-Encoding 
< Transfer-Encoding: chunked 
< 
{ 
"azp": "[redacted].apps.googleusercontent.com", 
"aud": "[redacted].apps.googleusercontent.com", 
"sub": "[redacted]", 
"scope": "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar", 
"exp": "1476831626", 
"expires_in": "3581", 
"email": "[redacted]", 
"email_verified": "true", 
"access_type": "offline" 
} 
* Connection #0 to host www.googleapis.com left intact 


$ curl -v https://www.googleapis.com/calendar/v3/users/me/calendarList?access_token=[redacted] 
* Trying 216.58.195.74... 
* Connected to www.googleapis.com (216.58.195.74) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 
* Server certificate: *.googleapis.com 
* Server certificate: Google Internet Authority G2 
* Server certificate: GeoTrust Global CA 
> GET /calendar/v3/users/me/calendarList?access_token=[redacted] HTTP/1.1 
> Host: www.googleapis.com 
> User-Agent: curl/7.49.1 
> Accept: */* 
> 
< HTTP/1.1 401 Unauthorized 
< Vary: X-Origin 
< WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token 
< Content-Type: application/json; charset=UTF-8 
< Date: Tue, 18 Oct 2016 22:01:14 GMT 
< Expires: Tue, 18 Oct 2016 22:01:14 GMT 
< Cache-Control: private, max-age=0 
< 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,33,32" 
< Accept-Ranges: none 
< Vary: Origin,Accept-Encoding 
< Transfer-Encoding: chunked 
< 
{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "authError", 
    "message": "Invalid Credentials", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Invalid Credentials" 
} 
} 
* Connection #0 to host www.googleapis.com left intact 
+0

做任何其他調用的工作? – DaImTo

+0

您的刷新令牌可能已過期嗎? – luc

+0

@luc如果刷新令牌已過期,我可以使用它來獲取新的訪問令牌,並且我已擁有的訪問令牌不適用於tokeninfo端點。 –

回答

0

我能夠通過創建一個谷歌應用程序用戶,其子組織已關閉Google日曆來重現這種情況。 Google仍然允許用戶授予日曆訪問權限,並表示已授予範圍,但在嘗試使用其訪問令牌調用任何Google Calendar API終端節點時,將按照說明的方式執行401。

谷歌,當請求訪問已被管理員關閉的應用程序時,請讓您的錯誤信息更清楚或阻止初始範圍授權!