如何在Google Drive API上按文件夹获取文件列表 [英] How to get list of files by folder on Google Drive API

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

问题描述

我正在尝试为用户导航他/她的Google云端硬盘并选择一个或多个文档以供稍后在数据库的网站中引用。我目前正在使用.NET构建一个Web界面。
我面临的问题是我找不到一个函数来获取文件夹Id的文件列表。
我尝试过使用:

... www.googleapis.com/drive/v2/files/BB0CHANGEDIDF5waGdzbUQ5aWs/children



...但这只会给出文件夹内所有文件的引用ID(即所谓的子资源项),这意味着我必须遍历这些文件并创建一个为了获得我需要的所有元数据,请求他们中的每一个为我的用户界面。
不幸的是..



... www.googleapis.com/drive/v2/files



..将按文件夹列出所有我的文件,没有过滤选项。
我想知道是否有一种有效的方法提取文件夹&文件列表从一次调用驱动器服务器的特定文件夹。

我也试过这个(基于对类似问题的答案):
我使用Fiddler来直接调用api。当我使用这个来拨打电话时



... www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'



出现错误:

  {
错误:{
errors:[
{wrongID
domain:global,
reason:invalid,
message :无效值,
locationType:parameter,
location:q
}
],
code:400 ,
message:无效值
}
}



<即使使用谷歌的测试页面也没有这样做。
它看起来像文件端点不接受任何参数。


必须有一种方法来实现这一点!



感谢您的帮助

解决方案

您应该可以只需在父查询中使用文件/列表;

  GET https://www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'+in+parents&key={YOUR_API_KEY } 


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 .NET. The problem I am facing is that I can not find a single function to get a list of files by folder Id. I tried using:

...www.googleapis.com/drive/v2/files/BB0CHANGEDIDF5waGdzbUQ5aWs/children

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

...www.googleapis.com/drive/v2/files

..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 by for a specific folder.

I also tried this (based on answer to the similar issue): I am using Fiddler to do direct calls to the api. When I use this to make the call `

...www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'

I get an error:

{
 "error": {
  "errors": [
   {wrongID
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value",
    "locationType": "parameter",
    "location": "q"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

Even using google's test page does not do it. It looks like the "files" endpoint does not accept any parameter.

There has to be a way to achieve this!

Thank you for your help

解决方案

You should be able to simply use files/list with a parent query;

GET https://www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'+in+parents&key={YOUR_API_KEY}

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

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