Google Drive API children.list [英] Google Drive API children.list

查看:85
本文介绍了Google Drive API children.list的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript代码列出Google云端硬盘根目录中所有文件的名称.仅供参考:我是javascript的新手.

对于第一个功能,我从 https://developers.google复制了代码.com/drive/v2/reference/children/list .

接下来的两个功能是我自己的代码.我的结果只是一堆"[对象对象],[对象对象],[对象对象],[对象对象]".此输出与我在Google云端硬盘的根文件夹中拥有的文件数匹配.但是,我想要文件名或id,但是除了"[object Object]"之外,我似乎什么也没得到.

我尝试将"resp.items"更改为"resp.kind"或"resp.selflink",但是我只是得到了"undefined".有人知道如何获取文件上的任何特定信息吗?如果很重要,范围为" https://www.googleapis.com/auth/drive .

function retrieveAllFilesInFolder(folderId, callback) {
  var retrievePageOfChildren = function(request, result) {
    request.execute(function(resp) {
      result = result.concat(resp.items);
      var nextPageToken = resp.nextPageToken;
      if (nextPageToken) {
        request = gapi.client.drive.children.list({
          'folderId' : folderId,
          'pageToken': nextPageToken
        });
        retrievePageOfChildren(request, result);
      } else {
        callback(result);
      }
    });
  }
  var initialRequest = gapi.client.drive.children.list({
      'folderId' : folderId
    });
  retrievePageOfChildren(initialRequest, []);
}



function printToOutdiv (result){document.getElementById("outdiv").innerHTML=result;}

function GetFilesButton (){
    gapi.client.load('drive', 'v2', function() {retrieveAllFilesInFolder('root',printToOutdiv);} );
}  

解决方案

获得的结果是可以按索引访问的对象数组,如result[0]result[1]等. >

一旦获得对这些对象之一的引用,就可以像result[0].id中那样访问其属性(例如id).

I'm trying to make javascript code to list the names of all the files in the root directory of Google Drive. FYI: I'm new to javascript.

For the first function, I copied code from https://developers.google.com/drive/v2/reference/children/list .

The next two functions are my own code. My results is just a bunch of "[object Object],[object Object],[object Object],[object Object]". This output matches the number of files I have in the root folder of my Google Drive. However, I want the file names or id's, but I can't seem to get anything besides "[object Object]".

I tried changing the "resp.items" to "resp.kind" or "resp.selflink" but then I just get "undefined". Anyone know how to get any specific information on the files? In case it matters, scope is "https://www.googleapis.com/auth/drive".

function retrieveAllFilesInFolder(folderId, callback) {
  var retrievePageOfChildren = function(request, result) {
    request.execute(function(resp) {
      result = result.concat(resp.items);
      var nextPageToken = resp.nextPageToken;
      if (nextPageToken) {
        request = gapi.client.drive.children.list({
          'folderId' : folderId,
          'pageToken': nextPageToken
        });
        retrievePageOfChildren(request, result);
      } else {
        callback(result);
      }
    });
  }
  var initialRequest = gapi.client.drive.children.list({
      'folderId' : folderId
    });
  retrievePageOfChildren(initialRequest, []);
}



function printToOutdiv (result){document.getElementById("outdiv").innerHTML=result;}

function GetFilesButton (){
    gapi.client.load('drive', 'v2', function() {retrieveAllFilesInFolder('root',printToOutdiv);} );
}  

解决方案

The result you are getting is an array of objects that you can access by index, as in result[0], result[1], and so on.

Once you get a reference to one of those objects, you can access its properties (e.g. the id) as in result[0].id.

这篇关于Google Drive API children.list的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆