1

这是对Google Drive Realtime API OAuth2 Refresh Errors的跟进。

自从周三推送了实时 API 的更新以来,我一直看到一些关于刷新 OAuth 令牌的额外问题。OAuth 令牌过期后,实时 API 按预期收到 401 错误,并在文档上引发错误事件。此错误已得到处理,应用程序通过 gapi.auth.authorize 请求新的 OAuth 令牌,该令牌已在 gapi.auth 中成功设置(使用 getToken 验证)。但是,实时 api 似乎并未使用此令牌,该 api 使 stacuk 处于永久上传状态,但不会引发任何错误。

>>>> Page Load <<<<
1374822961806 ": GAPI Authorized" 
Object {state: "", access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_DloepHbGho", token_type: "Bearer", expires_in: "3600", client_id: "XXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"…}
_aa: "1"
access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_DloepHbGho"
client_id: "XXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1374826561"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1374822961"
response_type: "token"
scope: Array[2]
state: ""
token_type: "Bearer"

>>>> Document loaded successfully <<<<
Remote Size:  130.24 kB
Remote String Size:  22.01 kB
Final Remote Item Counts:
  Map :  409
  List :  118
  EditableString :  407
Total Inaccessible Items: 8
Total Unused Lists: 14

>>>> Wait for OAuth2 Token Timeout <<<<
GET https://drive.google.com/otservice/bind?id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX…RID=rpc&SID=XXXXXXXXXXXXXXXXXXXXXXXXXXX&CI=0&AID=206&TYPE=xmlhttp&zx=7cirt7mulog0&t=1 401 (Unauthorized) api:87
Drive Realtime API Error: token_refresh_required: The OAuth token must be refreshed. api:477
Doc Load Error:  Sx {type: "token_refresh_required", message: "The OAuth token must be refreshed.", b: false, isFatal: false}

>>>> Handle Doc Load Error <<<<
1374826571645 ": Refreshing OAuth2 Token: " 
["https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/userinfo.email"]

>>>> Before refreshing call gapi.auth.getToken() <<<<
1374826571646 ": Current Token: " null

>>>> Refresh using gapi.auth.authorize() and do NOT call gapi.auth.setToken() <<<<
1374826571813 ": Refreshed OAuth2 Token: " 
Object {state: "", access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_qnWk1NXWXHCmi", token_type: "Bearer", expires_in: "3600", client_id: "XXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"…}
_aa: "1"
access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_qnWk1NXWXHCmi"
client_id: "XXXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1374830171"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1374826571"
response_type: "token"
scope: Array[2]
state: ""
token_type: "Bearer"

>>>> After refreshing call gapi.auth.getToken() <<<<
1374826571814 ": New Token: " 
Object {state: "", access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_qnWk1NXWXHCmi", token_type: "Bearer", expires_in: "3600", client_id: "XXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"…}
_aa: "1"
access_token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_qnWk1NXWXHCmi"
client_id: "XXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
cookie_policy: undefined
expires_at: "1374830171"
expires_in: "3600"
g_user_cookie_policy: undefined
issued_at: "1374826571"
response_type: "token"
scope: Array[2]
state: ""
token_type: "Bearer"

>>>> At this point the document is stuck in isPending and isSaving <<<<
>>>> Modifications to the document don't error but don't persist <<<<

这是一个已知问题还是有更好的方法来处理这种情况?据我所知,这是根据顶部链接的先前帖子处理令牌刷新的正确方法。

4

0 回答 0