简体   繁体   English

列出Google Drive SDK中的所有文件夹及其文件

[英]List All Folders and their files in Google Drive SDK

I am using Google Drive SDK to get a list of my files and display them on my site! 我正在使用Google Drive SDK获取我的文件列表并将其显示在我的网站上! I am using a service account for server-side integration! 我正在使用服务帐户进行服务器端集成!

I have like 4-5 folders in my root directory and 50-60 files in each of them! 我的根目录中有4-5个文件夹,每个文件夹中有50-60个文件! What scopes should I use and what method should I use so as to retrieve all the folders and then their sub files? 我应该使用什么范围以及我应该使用什么方法来检索所有文件夹然后检索它们的子文件?

I cant seem to find documentation for getting folders or so! 我似乎无法找到获取文件夹的文档等等! In v2 it was by using childrens method but PHP SDK is on v3. 在v2中,它使用了儿童方法,但PHP SDK在v3上。

My flow would be like this. 我的流程就像这样。

Authenticate using service acccount->get list of folders->get list of files inside this folder->display them. 使用服务acccount->获取文件夹列表进行身份验证 - >获取此文件夹中的文件列表 - >显示它们。

First make sure you understand that a Service Account is not your personal Google account . 首先请确保您了解服务帐户不是您的个人Google帐户 So unless you share all your folders, you will not be able to access your files by authenticating using a Service Account. 因此,除非您共享所有文件夹,否则您将无法通过使用服务帐户进行身份验证来访问您的文件。 See How do I authorise an app (web or installed) without user intervention? 请参阅如何在没有用户干预的情况下授权应用程序(Web或已安装)? (canonical ?) (规范?)

Once you are authenticating using the correct credentials. 使用正确的凭据进行身份验证后。 The best approach is to:- 最好的方法是: -

  1. Authenticate using your own credentials 使用您自己的凭据进行身份验证
  2. List all of your folders files.list q='mimetype=application/vnd.google-apps.folder and trashed=false 列出所有文件夹files.list q='mimetype=application/vnd.google-apps.folder and trashed=false
  3. For those folder ids you wish to see the children files.list q=parents in (id1, id2,...) and trashed = false 对于那些文件夹ID,您希望看到子文件files.list q=parents in (id1, id2,...) and trashed = false

See How do I search sub-folders and sub-sub-folders in Google Drive? 请参阅如何在Google云端硬盘中搜索子文件夹和子子文件夹? for some background on how folders work. 了解文件夹如何工作的背景知识。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM