在過去幾天裏,我看到一些長期運行的實時應用程序出現了一些問題日益嚴重的問題。我已經完成了下面的步驟,底部的代碼片段包含了來自應用的其他調試信息。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錯誤以僅更新標記足以解決重複的錯誤問題。感謝您及時的回覆! –