我正在尝试创建一个程序,它将在我的google驱动器中下载图像文件。我能够这样做,但是当我尝试搜索文件以返回特定文件时,我总是在使用' name'该网站基于此网站https://developers.google.com/drive/v3/web/search-parameters。我真的不知道这个问题。这是我的代码
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;
}
答案 0 :(得分:1)
如果我们查看文档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进行了更新,您猜测它使用的是名称而不是文件的标题。
IMO应该有两个,因为它只是不同的API。