2012-04-26 117 views
-1

我剛剛下載了newsest doc list api,並嘗試一下。下面我的代碼:Google docs 3.0 java API上傳文件無法正常工作

DocsService client = new DocsService("testappv3"); 
client.setUserCredentials("username", "password"); 
File file = new File("c:/test.txt"); 
URL url = new URL("https://docs.google.com/feeds/defaults/private/full/"); 
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType(); 
DocumentEntry newDocument = new DocumentEntry(); 
newDocument.setTitle(new PlainTextConstruct("test")); 
//newDocument.setMediaSource(new MediaFileSource(file, mimeType)); 
newDocument.setFile(file, mimeType); 
newDocument = client.insert(url, newDocument); 

誤差低於:

com.google.gdata.util.ResourceNotFoundException: Not Found 
<HTML> 
<HEAD> 
<TITLE>Not Found</TITLE> 
</HEAD> 
<BODY BGCOLOR="#FFFFFF" TEXT="#000000"> 
<H1>Not Found</H1> 
<H2>Error 404</H2> 
</BODY> 
</HTML> 

回答

1

你的URI是不正確的:

https://docs.google.com/feeds/defaults/private/full/ 

應該

https://docs.google.com/feeds/default/private/full/ 

(無S)

+0

好,它的工作原理,但如果我添加'newDocument.setTitle(new PlainTextConstruct(「test」));'會得到一個錯誤'com.google.gdata.util.ServiceException:發生未知錯誤。 <錯誤的xmlns = 'HTTP://schemas.google.com/g/2005'>的GDataServiceException已發生未知的錯誤'。這是否意味着我不能爲我的文檔提供一個新名稱? – user1335794 2012-04-27 08:04:47

+0

您應該爲此詢問一個新問題。 – 2012-04-27 17:04:13