2016-07-23 56 views
0

我正在使用以下代碼從我的谷歌驅動器的根文件夾中檢索所有文件。Drive Api v3不會返回根文件夾中的所有文件

List<File> result = new ArrayList<File>(); 
      Files.List req = null; 

      try { 
        req = driveService.files().list(); 
        FileList files = req.setQ("'root' in parents and trashed=false").execute(); 
        result.addAll(files.getFiles());   
        req.setPageToken(files.getNextPageToken()); 
       } 
       catch (IOException e) 
       { 
       System.out.println("An error occurred: " + e); 
       req.setPageToken(null); 
       } 

      //Print out all the files and folder of root Directory 
      for(File f:result) 
      { 
       System.out.println("recvd data are: "+f.getName()); 
      } 

但問題是,仍然不是所有的文件都被檢索,而是總是隻有14個文件從驅動器返回。任何人都可以請指導我哪裏出錯。

感謝,

+0

你還在遇到這個問題嗎? –

回答

0

根文件夾也可以命名爲'root'一個特殊的別名地址,這樣你就可以在根的所有文件和文件夾下面的查詢:

HTTP請求:

https://www.googleapis.com/drive/v2/files?q='root' *in parent 

使用別名root作爲參數folderId以列出根文件夾中的所有文件。所有對Google Drive API的請求都必須由經過身份驗證的用戶授權。 Google雲端硬盤使用OAuth 2.0協議驗證Google帳戶並授權訪問用戶數據。您也可以使用OAuth 2.0

List<File> result = new ArrayList<File>(); 
Files.List request = null; 

try { 
request = mService.files().list(); 
FileList files = request.setQ("'root' in parents and trashed=false").execute(); 
result.addAll(files.getItems()); 
request.setPageToken(files.getNextPageToken()); 
} 
catch (IOException e) 
{ 
System.out.println("An error occurred: " + e); 
request.setPageToken(null); 
} 

//Print out all the files and folder of root Directory 
for(File f:result) 
{ 
System.out.println("recvd data are: "+f.getTitle()); 
} 
相關問題