在过去几天里,我看到一些长期运行的实时应用程序出现了一些问题日益严重的问题。我已经完成了下面的步骤,底部的代码片段包含了来自应用的其他调试信息。Google Drive实时API OAuth2刷新错误
页面首次打开时,它成功地请求OAuth令牌并加载实时文档[A]。 50分钟后(令牌到期前10分钟),它会成功重新申请一个新的OAuth令牌[B]。第一个令牌过期后,当前打开的连接会获得401未经授权的错误,并需要新的oauth令牌[C]。这本身就像是一个问题,因为它应该更新自己以使用[B]中的新有效标记。
然而,应用程序仍然应该对这样的错误具有适应性 - 因此可以通过关闭并重新打开文档[D]并获取另一个新的OAuth令牌来处理。不幸的是,在这一点上,实时API位于无限循环中,获取access_token [E]的错误。
所有OAuth令牌都使用gapi.auth.authorize使用相同的作用域并且没有对setToken的调用请求。我以前尝试过使用setToken,但这有完全相同的问题。
实际问题 处理刷新实时API的OAuth令牌的正确方法是什么?在关闭和重新打开文档时,如何防止驱动器API内部发生重复故障?
[A]
_aa: "1"
access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXz9AYBkyympssqI"
client_id: "XXXXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1373610287"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1373606687"
response_type: "token"
scope: Array[2]
state: ""
token_type: "Bearer"
[B]
_aa: "1"
access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXV2kzG4EMUppi"
client_id: "XXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1373613288"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1373609688"
response_type: "token"
scope: Array[2]
state: ""
token_type: "Bearer"
[C]
GET https://drive.google.com/otservice/bind?id=1B-XXXXXXXXXXXXXXXXXXXXX_nRizfqmT…&RID=rpc&SID=XXXXXXXXXXXXXXXXX&CI=0&AID=221&TYPE=xmlhttp&zx=ns6e5dr7rf4&t=1 401 (Unauthorized)
Drive Realtime API Error: token_refresh_required: The OAuth token must be refreshed.
[D]
[Close Realtime Document]
[Open Realtime Document]
_aa: "1"
access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXMHzJXm2dF-"
client_id: "XXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1373613918"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1373610318"
response_type: "token"
scope: Array[2]
state: ""
token_type: "Bearer"
[E]
[x100] Uncaught TypeError: Cannot read property 'o' of null
谢谢!
处理token_refresh_required错误以仅更新标记足以解决重复的错误问题。感谢您及时的回复! –