2016-09-23 6 views
1

Googleドライブに画像ファイルをダウンロードするプログラムを作成しようとしています。私はそうすることができましたが、特定のファイルを返すためにファイルを検索しようとしているとき、私はいつもこのウェブサイトのベースである「名前」フィールドを使用するとエラーが発生しましたhttps://developers.google.com/drive/v3/web/search-parameters。私は本当に問題を知らない。我々はドキュメントSearch for FilesGoogleドライブでダウンロードするファイルを検索するC#

name string contains1, =, != Name of the file. 

をチェックするとこれがまたそれが

name contains 'hello' and name contains 'goodbye' 

を使用している示して私のコード

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; 
    } 

答えて

1

で今file.list方法は、ファイルのリソースのリストを返します。あなたがfile resourcesの名前をチェックする場合は、パラメータではありませんtitleです。

あなたがもしそうなら

mimeType='image/jpeg' and (title contains 'a') 

リクエストが動作します。

ドキュメントが間違っている理由は、Googleドライブv2 APIを使用していることと、ファイルのタイトルではなく名前を使用すると思われるGoogleドライブv3のドキュメントが明らかに更新されていることです。

IMOここではちょうど異なるAPIがあるため、2つあるはずです。

+0

説明と助けをありがとう。 – user3928241

関連する問題