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

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

问题描述

我正在尝试构建一个网络用户界面,供用户浏览他/她的 Google 云端硬盘并选择一个或多个文档,以便稍后在网站中从数据库中引用.我目前正在使用 PHP 构建 Web 界面.

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.

我面临的问题是我找不到一个函数来按文件夹 ID 获取文件列表.

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

我尝试使用:

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

...但这只会给出文件夹中文件的文件引用 ID(所谓的子资源项),这意味着我必须遍历这些文件并为每个文件创建一个调用才能获取我的 UI 所需的所有元数据.

…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.

不幸的是..

$service->files->list()

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

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

我想知道是否有一种有效的方法可以从对 Drive 服务器的一次调用中提取文件夹文件列表.我实际上记得能够通过旧的 Google DOC API 执行此任务.

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.

非常感谢您的帮助

推荐答案

注意这个答案使用 v2 API.新应用程序应写入 v3 API.

现在可以使用 drive.files.list 端点了列出属于特定文件夹的文件.

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

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

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"

在 PHP 中是

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

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

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