2013-07-17 34 views
0

下面是我用來查找包含志願者文件列表的代碼。查詢字符串搜索文件不適用於谷歌驅動器API

private static List<File> retrieveAllFiles(Drive service) throws IOException { 
    List<File> result = new ArrayList<File>(); 
    Files.List request = service.files().list().setQ("Volunteers"); 
    System.out.println("Request size:" + request.size()); 
    do { 
     try { 
      FileList files = request.execute(); 
      System.out.println("Request files size:" + files.size()); 
      result.addAll(files.getItems()); 
      request.setPageToken(files.getNextPageToken()); 
     } catch (IOException e) { 
      System.out.println("An error occurred: " + e); 
      request.setPageToken(null); 
     } 
    } while (request.getPageToken() != null && 
      request.getPageToken().length() > 0); 

    return result; 
} 

在執行時,它返回

[s~sakshumweb-hrd/3.368839385999923807].<stdout>: An error occurred: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 OK 
{ 
    "code" : 400, 
    "errors" : [ { 
    "domain" : "global", 
    "location" : "q", 
    "locationType" : "parameter", 
    "message" : "Invalid Value", 
    "reason" : "invalid" 
    } ], 
    "message" : "Invalid Value" 
} 

有什麼不妥的地方。

回答

3

當你想要「查找包含志願者的文件列表」時,我不太確定你想要搜索什麼,但是你應該指定從哪個文件資源中搜索你的查詢。

例如,如果您要在標題中搜索包含「志願者」的文件,您的代碼應該是service.files().list().setQ("title contains 'Volunteers'");,或者如果要搜索文件的標題和內容以查看它們是否包含「志願者」代碼應該看起來像service.files().list().setQ("fullText contains 'Volunteers'"); 請仔細看看search parameters documentation。它會讓你更好地瞭解如何搜索文件。

+0

謝謝,現在不會返回任何錯誤。但是,即使現在它也不能打印文件。以下是打印結果的代碼: 列表 files = retrieveAllFiles(service); System.out.println(「list size is:」+ files.size());對於(int i = 0; i :列表大小爲:0 – Vik

+0

這意味着在標題或內容中沒有包含志願者的文件。請在「查找包含志願者的文件列表」中指定您的意思並給出您使用的q參數。 –

+0

Files.List request = service.files().list().setQ(「title contains'Volunteer'」);這是字符串,我的驅動器有一個文件名志願者信息表 – Vik

相關問題