在Drive SDK上按文件夹获取文件列表 [英] Getting a list of files by folder on Drive SDK

查看:84
本文介绍了在Drive SDK上按文件夹获取文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为用户导航他/她的Google云端硬盘并选择一个或多个文档以供稍后在数据库的网站中引用。我正在使用PHP构建一个Web界面。



我遇到的问题是我无法找到一个函数来获取文件夹Id的文件列表。

我尝试过使用:

  $ service-> children-> listChildren($ rootFolderId)

...但这只会给出文件夹内文件的参考ID (所谓的儿童资源项目),这意味着我必须遍历这些文件,并为其中的每一个创建一个调用,以便获取我的UI所需的所有元数据。



不幸的是,

  $ service-> files-> list()
code>

..将按文件夹列出所有我的文件,没有过滤选项。



我想知道是否有一种有效的方法可以将单个文件夹文件列表从Drive服务器中提取出来。我真的记得能够对旧的Google DOC API执行此操作。



非常感谢您的帮助

解决方案

现在可以使用该驱动器 。 files.list endpoint列出属于特定文件夹的文件。



为此,您可以使用?q = 查询参数如下:

  GET https://www.googleapis.com/drive/v2/files?q=父母中的''< FOLDER_ID>'

在PHP中,这将是

  $ service-> files-> list(array('q'=>''父母中的'< FOLDER_ID>)) ; 


I am trying to build a web UI for users to navigate his/her Google Drive and select one or more documents to be referenced later on in a website from a DB. I am currently building a web interface using PHP.

The problem I am facing is that I cant find a single function to get a list of files by folder Id.

I tried using:

$service->children->listChildren($rootFolderId)

…but that will only give the files reference ID of the files within the folder (the so called children resource item), which means I have to loop through those files and create a call for each one of them in order to get all the metadata I need for my UI.

Unfortunately..

$service->files->list()

..will list ALL my files with no filtering options by folder.

I would like to know if there is an efficient way of extracting a folder file list from a single call to the Drive server. I actually remember being able to perform this taks over the old Google DOC API.

Thank you very much for your help

解决方案

It is now possible to use the drive.files.list endpoint to list files belonging to a specific folder.

To do so, you can use the ?q= query parameter as follows:

GET https://www.googleapis.com/drive/v2/files?q="'<FOLDER_ID>' in parents"

In PHP, that would be

$service->files->list(array('q' => "'<FOLDER_ID>' in parents"));

这篇关于在Drive SDK上按文件夹获取文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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