问题描述
我们正在尝试将Google云端硬盘纳入我们应用程序的文档存储库.我们正在使用Google Drive API V3来访问Google Drive API.在此过程中,我们在实现某些功能方面面临的挑战很少.以下是约束.
We are trying to incorporate Google Drive as a document repository for our application. We are using Google Drive API V3 for accessing Google Drive API. In this process, we are facing few challenges for implementing some of the features. The following are the constraints.
-
我们正尝试仅在特定文件夹内检索文件夹和文件.但是目前我们无法实现它们.
We are trying to retrieve the folders and files only inside a particular folder. But Currently we cannot able to achieve them.
检索时是否有任何规定可以按照文件和文件夹在Google云端硬盘中的确切位置顺序进行排序?
When retrieving is there any provision to order files and folders in the exact hierarchy of how it is located in the Google Drive?
在检索文件和文件夹时,我们可以看到已经从驱动器中删除的文件夹和文件.
When retrieving the files and folders, we could able to see the folders and files which are deleted from drive already.
您能帮助我们实现这些目标吗?
Could you please help us on how to achieve them.
推荐答案
简单的REST API请求:带有https://www.googleapis.com/drive/v3/files 的q参数,您可以在其中指定查询以及要搜索的内容.例如:
Simple REST API request to: https://www.googleapis.com/drive/v3/files with q parametr, where you specify the query, what you want to search.For example:
mimeType = 'application/vnd.google-apps.folder' // list only folders
'root' in parents // only files (or folders) that are in root folder (have root in parents)
此处完整的指南: https://developers.google.com/drive/api/v3/search-文件
在这里您可以找到游乐场,在右侧您可以尝试API: https://developers.google.com/drive/api/v3/参考/文件/列表
Complete guide here:https://developers.google.com/drive/api/v3/search-files
Here you have playground, on the right side you can try the API:https://developers.google.com/drive/api/v3/reference/files/list
对我来说,最大的问题是,如何将这些参数传递给URL,魔术是编码URIComponent(在javascript中),因此完整的URL来自: https://www.googleapis.com/drive/v3/files?q=mimeType ='application/vnd.google-apps.folder'和'root'在父母中
The biggest issue for me was, how to pass these parameters to the URL, the magic is to encodeURIComponent (in javascript), so your complete URL gets from:https://www.googleapis.com/drive/v3/files?q=mimeType = 'application/vnd.google-apps.folder' AND 'root' in parents
to
https://www.googleapis.com/drive/v3/files?q=mimeType%20%3D%20'application%2Fvnd.google-apps.folder'%20AND%20'root'%20in%20parents
那Google一定会明白的.不要忘记在授权标头中发送您的Google令牌,例如:
And that will Google definitely understand. Don't forget to send your google token in Authorization header, e.g.:
headers: {
Authorization: `Bearer ${user.google_token}`,
'Content-Type': 'application/json',
},
这篇关于Google云端硬盘v3-无法从特定的文件夹ID检索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!