2012-10-19 90 views
0

我目前正在製作一個應用程序,可以從谷歌驅動器上傳和下載文件。 我在使用Drive SDK的android上開發。 問題是,每次我試圖從文件我該怎麼上傳設置修改日期,我總是得到壞請求錯誤400,這是我的喀嚓代碼:錯誤400錯誤的請求上傳使用驅動器API

protected CDriveFile doInBackground(String... file) { 
     // TODO Auto-generated method stub 
     com.google.api.services.drive.model.File f=null; 
     File a=new File(file[1]); 
     com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File(); 
     body.setTitle(file[1].substring(file[1].lastIndexOf("/")+1, file[1].length())); 
     Uri selectedUri = Uri.fromFile(a); 
     String fileExtension 
     = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString()); 
     String mimeType 
     = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); 
     body.setMimeType(mimeType); 
     body.setModifiedDate(DateTime.parseRfc3339(file[2])); 
     //without this, work well.. body.setModifiedDate(DateTime.parseRfc3339(file[2])); 
     FileContent mediaContent = new FileContent(mimeType, a); 
     try { 
      f = service.files().insert(body, mediaContent).execute(); 
      } 

文件沒有任何錯誤上傳當我沒有設定修改日期。從我知道我已經提供正確的日期格式爲Google Drive這是RFC3339,糾正我,如果我錯了。 我真的很感激所有你的任何答覆和關注..

+0

有時,400錯誤提供了比只是「錯誤的請求」的更多細節。你有這樣的細節嗎? – Jerome

回答

1

在驅動器API的參考,我們對modifiedDate這樣的描述:

上次這個文件是由人(格式化RFC 3339修改 時間戳)。 只有在setModifiedDate 參數設置爲時,此更新纔可更新。

,所以我想你不能直接設置修改日期插入

+0

我試圖在更新文件內容上設置修改日期,但這對我來說不是運氣。我仍然有錯誤400錯誤的請求。這是我使用的代碼,我錯了這個'body.setModifiedDate(new DateTime(a.lastModified()));' – KevinL

相關問題