使用gapi.client.request,我可以从Drive成功检索。
但是,如果我使访问令牌无效并再次尝试,我会按预期获得401,然后调用https://accounts.google.com/o/oauth2/auth?scope=&immediate=true&proxy=oauth2relay530384583&redirect_uri=postmessage&origin=http%3A%2F%2Fdev.myapp.co%3A9000&response_type=token&state=780297101%7C0.3257751071&authuser=0
失败400“缺少所需参数:范围”
查看URL,范围确实是空的,但为什么呢?
在身份验证开始时,我正在使用数组设置我的范围...
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
});