谷歌驱动器API,JavaScript列表文件没有返回 [英] google drive api, javascript list files returns nothing
问题描述
我刚开始使用Drive API调用,并试图列出我的文件。
到目前为止,我的函数如下所示:
var retrieveAllFiles = function(){
var retrievePageOfFiles = function(request,result){
request.execute(function(resp){
console.log(resp);
result = result .concat(resp.items);
var nextPageToken = resp.nextPageToken;
console.log(nextPageToken =+ nextPageToken);
if(nextPageToken){
request = gapi.client.drive.files.list({'pageToken':nextPageToken});
retrievePageOfFiles(request,result);
} else {
printFileList(result);
}
});
}
var initialRequest = gapi.client.drive.files.list({'maxResults':10});
console.log(initialRequest =+ initialRequest);
retrievePageOfFiles(initialRequest,[]);
}
在firebug中,我看到响应如下所示:
[
{
id:gapiRpc,
result:{
kind:drive#fileList,
etag:\vGmlhiWxP02tugPmRvLynwC_A0Y / vyGp6PvFo4RvsFtPoIWeCReyIC8 \
}
}
]
这不是我所期望的,因为我的云端硬盘包含两个文件。
任何人都可以指出我的错误是什么?
谢谢
我自己解决了这个问题,这是一个范围问题。
我正在使用
https://www.googleapis.com/auth/drive.file
但这只允许访问由创建请求的应用程序创建的文件。要访问我必须添加的所有文件
https://www.googleapis.com/auth/drive
我只是通过使用其他应用程序计算出来的,并注意到它需要不同的范围。
I'm just getting started with Drive API calls, and I'm trying to list my files.
So far, my function looks like this:
var retrieveAllFiles = function () {
var retrievePageOfFiles = function(request, result) {
request.execute(function(resp) {
console.log(resp);
result = result.concat(resp.items);
var nextPageToken = resp.nextPageToken;
console.log("nextPageToken ="+nextPageToken);
if (nextPageToken) {
request = gapi.client.drive.files.list({'pageToken': nextPageToken});
retrievePageOfFiles(request, result);
} else {
printFileList(result);
}
});
}
var initialRequest = gapi.client.drive.files.list({'maxResults': 10});
console.log("initialRequest = "+initialRequest);
retrievePageOfFiles(initialRequest, []);
}
In firebug, I see that the response looks like this:
[
{
"id": "gapiRpc",
"result": {
"kind": "drive#fileList",
"etag": "\"vGmlhiWxP02tugPmRvLynwC_A0Y/vyGp6PvFo4RvsFtPoIWeCReyIC8\""
}
}
]
This isn't what I expect, because my Drive contains two files.
Can anyone point out what my mistake is?
Thanks
I've solved this one myself it was a problem with scopes.
I was using
https://www.googleapis.com/auth/drive.file
but this only grants access to files create with the app making the request. To get access to all the files I had to add
https://www.googleapis.com/auth/drive
I only figured it out by using another app and noticing it was asking for different scopes.
这篇关于谷歌驱动器API,JavaScript列表文件没有返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!