2012-02-23 36 views
2

我一直非常沮喪的谷歌API。每次我嘗試時,即使從各處收集了大量的罐子,它也是行不通的。我會很感激,如果有人能幫助我用下面的代碼 - >無法運行Google文檔的Google gdata API

import java.net.URL; 
import com.google.gdata.client.docs.DocsService; 
import com.google.gdata.data.docs.DocumentListEntry; 
import com.google.gdata.data.docs.DocumentListFeed; 


public class TestGoogleDocs { 

    public static void main(String[] args) { 
     try { 
      System.err.println("== Testing Google Docs =="); 
      DocsService docService = new DocsService("Document list"); 
      docService.setUserCredentials("*****@gmail.com", "******"); 

      URL documentFeedURL = new URL("http://docs.google.com/feeds/documents/private/full"); 

      DocumentListFeed docsFeed = docService.getFeed(documentFeedURL, DocumentListFeed.class); 

      for(DocumentListEntry entry: docsFeed.getEntries()){ 
       System.err.println(entry.getTitle().getPlainText()); 
      } 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

} 

我在classpath中添加以下jar文件:

gdata-client-1.0.jar 
gdata-client-meta-1.0.jar 
gdata-core-1.0.jar 
gdata-media-1.0.jar 
gdata-docs-3.0.jar 
gdata-docs-meta-3.0.jar 

activation.jar 
mail.jar 
servlet-api.jar 

guava-r09.jar 

錯誤,我得到的是:

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> 

    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:591) 
    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) 
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) 
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) 
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) 
    at com.google.gdata.client.Service.getFeed(Service.java:1135) 
    at com.google.gdata.client.Service.getFeed(Service.java:998) 
    at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631) 
    at com.google.gdata.client.Service.getFeed(Service.java:1017) 
    at com.javainsight.cloud.TestGoogleDocs.main(TestGoogleDocs.java:21) 

回答

3

我認爲URL是問題的URL - 請參閱下面的更多細節。

我認爲最好從gdata/java/sample/docs的示例代碼開始,並從示例中獲取DocumentListDocumentList異常類。

如果你這樣做,減少上面的例子:

import com.google.gdata.data.docs.DocumentListEntry; 
import com.google.gdata.data.docs.DocumentListFeed; 

public class Example { 

static public void main(String[] args) throws Exception { 
    DocumentList docList = new DocumentList("document"); 
    docList.login("********@gmail.com", "********"); 
    DocumentListFeed feed = docList.getDocsListFeed("all"); 
    for (final DocumentListEntry entry : feed.getEntries()) { 
     System.out.println(entry.getTitle().getPlainText()); 
    } 
    } 
} 

這個例子爲我工作(與R09番石榴JAR)。

跟蹤這個例子表明,生成的URL是

"https://docs.google.com/feeds/default/private/full" 
+0

非常感謝!它解決了我的問題。 – user381878 2012-03-05 06:27:07

0

是的,這也是我得到的。我想知道這個問題是否與Guava圖書館有關 - 我嘗試了Guava 11,但是在2011年10月發佈的當前gdata版本(2011年9月)之後,他們拿出了ImmutableSet.of(Object [] objs)調用。

我的第一個懷疑是網址......這就是我現在正在嘗試的。

0

我想補充一個音符爲別人誰可能有我有同樣的問題:

的網址只是罰款,但我使用的番石榴-11.0.1,嘗試番石榴-11.0.2,嘗試番石榴-14,而他們都沒有工作。看到這個後,我改用了guava-r09,效果很好。