Google drive api 获得;缺少必需参数:scope";使用Google Javascript API进行401测试后
使用gapi.client.request,我可以成功地从驱动器中检索 但是,如果我使访问令牌无效并重试,我会得到一个401,然后调用 400“缺少所需参数:范围”失败 看看URL,范围确实是空的,但为什么 在身份验证开始时,我使用数组设置作用域,因此Google drive api 获得;缺少必需参数:scope";使用Google Javascript API进行401测试后,google-drive-api,google-oauth,Google Drive Api,Google Oauth,使用gapi.client.request,我可以成功地从驱动器中检索 但是,如果我使访问令牌无效并重试,我会得到一个401,然后调用 400“缺少所需参数:范围”失败 看看URL,范围确实是空的,但为什么 在身份验证开始时,我使用数组设置作用域,因此 var scopes = [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleap
var scopes = [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile', "https://docs.googleusercontent.com/", "https://docs.google.com/feeds/",
"https://www.googleapis.com/auth/drive.install","https://www.googleapis.com/auth/tasks" ];
代码本身是
var request = gapi.client.request({
'path': '/drive/v2/files/'+qObject.id,
'method': 'GET',
'params': {'maxResults': '1'}
});
request.execute(function(resp) {
console.log(resp); // this get works as expected
});
// now invalidate the access token
var token=gapi.auth.getToken();
token.access_token = "foo";
gapi.auth.setToken(token);
request = gapi.client.request({
'path': '/drive/v2/files/'+qObject.id,
'method': 'GET',
'params': {'maxResults': '1'}
});
request.execute(function(resp) {
console.log(resp); // this fails with a 401 as expected, but fails to get a new token
});
根据,
scope
参数应该是“空格分隔的权限集”,而不是权限数组。构建url并发送url的代码在哪里?我猜缺少作用域是有原因的。代码在问题中。“var request=gapi.client.request(…);request.execute(…)”。记住,我的驾驶呼叫正在工作。如果访问令牌过期,则gapi客户机库响应401响应的方式不是。因此,完整的流程是:-获取访问令牌正常工作-从驱动器获取项目正常工作-使访问令牌无效以模拟3600秒后的到期-从驱动器获取项目按预期返回401,这是正常的-gapi库自动尝试身份验证,但URL有缺陷,然后文档链接失败指的是XHR调用,而不是作用域如何传递到Javascript库。JS库中的文档说“范围数组—授权的一个或多个范围”。您能告诉我们应该在哪里定义它吗?