无法运行Google文档的Google gdata API

问题描述:

我一直非常沮丧的谷歌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) 

我认为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

是的,这也是我得到的。我想知道这个问题是否与Guava图书馆有关 - 我尝试了Guava 11,但是在2011年10月发布的当前gdata版本(2011年9月)之后,他们拿出了ImmutableSet.of(Object [] objs)调用。

我的第一个怀疑是网址......这就是我现在正在尝试的。

我想补充一个音符为别人谁可能有我有同样的问题:

的网址只是罚款,但我使用的番石榴-11.0.1,尝试番石榴-11.0.2,尝试番石榴-14,而他们都没有工作。看到这个后,我改用了guava-r09,效果很好。