搜索文件在谷歌驱动器c下载#
问题描述:
我想创建一个程序,将下载图像文件在我的谷歌驱动器。我能够这样做,但是当我试图搜索文件以返回特定文件时,我总是在使用基于此网站https://developers.google.com/drive/v3/web/search-parameters的“名称”字段时出错。我真的不知道这个问题。这是我的代码搜索文件在谷歌驱动器c下载#
GoogleHelper gh = new GoogleHelper();//calling
DriveService service = GoogleHelper.AuthenticateServiceAccount(email, securityPath);
List<String> file = GoogleHelper.GetFiles(service,
"mimeType='image/jpeg' and name contains 'aa'");
String newFile = newPath+id;
gh.DownloadFile(service, file[0],newPath);
//get File Method:
public static List<String> GetFiles(DriveService service, string search)
{
List<String> Files = new List<String>();
try
{
//List all of the files and directories for the current user.
FilesResource.ListRequest list = service.Files.List();
list.MaxResults = 1000;
if (search != null)
{
list.Q = search;
}
FileList filesFeed = list.Execute();
// MessageBox.Show(filesFeed.Items.Count);
//// Loop through until we arrive at an empty page
while (filesFeed.Items != null)
{
// Adding each item to the list.
foreach (File item in filesFeed.Items)
{
Files.Add(item.Id);
}
// We will know we are on the last page when the next page token is
// null.
// If this is the case, break.
if (filesFeed.NextPageToken == null)
{
break;
}
// Prepare the next page of results
list.PageToken = filesFeed.NextPageToken;
// Execute and process the next page request
filesFeed = list.Execute();
}
}
catch (Exception ex)
{
// In the event there is an error with the request.
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message);
}
return Files;
}
答
如果我们查看文档Search for Files
name string contains1, =, != Name of the file.
它们还显示它正在使用
name contains 'hello' and name contains 'goodbye'
现在的方法的File.List返回文件的资源列表。如果您检查file resources名称不是参数title
是。
所以,如果你
mimeType='image/jpeg' and (title contains 'a')
您的请求将正常工作。
现在,文档出错的原因是您使用的是Google Drive v2 API,并且文档显然已经针对Google Drive v3进行了更新,您猜对此文档使用名称而不是标题。
国际海事组织应该有两个,因为它的只是不同的API在这里。
感谢您的解释和帮助。 – user3928241