2016-08-01 101 views
-1

我想下載與谷歌驅動器API的文件。該代碼沒有提供任何錯誤,但我無法在任何地方找到該文件。 這是代碼使用Google Drive API下載文件。無法在任何地方找到它

String fileId = "..."; 
    OutputStream outputStream = new ByteArrayOutputStream(); 

    try { 
    service.files().export(fileId, "text/csv") 
       .executeMediaAndDownloadTo(outputStream); 
} catch (IOException e) { 
    System.out.println("Ceva nu a mers bine"); 
    e.printStackTrace(); 
} 

    System.out.println(outputStream == null); 

任何ideea?

回答

0

基於此example in Google documentation,我沒有看到您的代碼有任何錯誤。

String fileId = "1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo"; 
OutputStream outputStream = new ByteArrayOutputStream(); 
driveService.files().export(fileId, "application/pdf") 
     .executeMediaAndDownloadTo(outputStream); 

確保您使用的是要下載的特定文件的正確fileId

您可以檢查以下鏈接:How to get Google Drive file IDHow to download a file from google drive using drive api java?

相關問題