【发布时间】:2017-07-01 01:06:29
【问题描述】:
gapi.drive.realtime 中存在一个错误,导致它无法与 auth2 (See this Github issue.) 一起使用。这里是错误的简要说明;使用旧的gapi.auth.authorize 方法时,gapi.drive.realtime 提供的功能可以正常工作:
gapi.auth.authorize({
client_id: 'client-id.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/drive.file',
immediate: true
}, (response) => {
if(response.error) {
console.log("Error signing in!");
console.log(response);
} else {
gapi.drive.realtime.load("file-id", (r) => console.log(r));
}
});
实时会话被创建并且生成的文档对象被记录到控制台并且没有错误。但是,如果将此代码更改为使用gapi.auth2中的等效功能:
gapi.auth2.authorize({
client_id: 'client-id.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/drive.file',
prompt: 'none'
}, (response) => {
if(response.error) {
console.log("Error signing in!");
console.log(response);
} else {
gapi.drive.realtime.load("file-id", (r) => console.log(r));
}
});
登录成功完成,但连接到文件时,记录以下错误:
GET https://drive.google.com/otservice/gs?rctype=js&rcver=0&id=file-id 401 ()
api:452 Drive Realtime API Error: token_refresh_required: The OAuth token must be refreshed.
查看网络调试器,第一次和第二次尝试的真正区别在于,在第二次尝试的过程中,gapi.drive.realtime 并没有在 header 中发送access_token,大概是因为它正在gapi.auth 中寻找它而不是gapi.auth2。这是错误。使用gapi.auth2.init 进行授权也会显示相同的行为。
我想知道是否有针对此错误的已知修复。是否有一些代码可以让gapi.drive.realtime 与gapi.auth2 中的函数一起使用,还是我只需要使用gapi.auth?
【问题讨论】:
标签: javascript google-authentication google-drive-realtime-api