1
我想創建一個程序,將下載圖像文件在我的谷歌驅動器。我能夠這樣做,但是當我試圖搜索文件以返回特定文件時,我總是在使用基於此網站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;
}
感謝您的解釋和幫助。 – user3928241