【问题标题】:Unable to run google gdata api for google docs无法为 google docs 运行 google gdata api
【发布时间】:2012-03-13 17:45:58
【问题描述】:

我对谷歌 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();
        }
    }

}

我在类路径中添加了以下 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)

【问题讨论】:

    标签: java gdata gdata-api


    【解决方案1】:

    我认为 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 guava JAR)。

    跟踪这个例子表明生成的 URL 是

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

    【讨论】:

      【解决方案2】:

      是的,我也是这样。我想知道这个问题是否与 Guava 库有关——我尝试了 Guava 11,但他们在当前 gdata 发布(2011 年 9 月)之后于 2011 年 10 月取消了 ImmutableSet.of(Object[] objs) 调用。

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

      【讨论】:

        【解决方案3】:

        我想为可能遇到与我相同问题的其他人添加一条注释:

        网址很好,但我用的是 guava-11.0.1,试过 guava-11.0.2,试过 guava-14,都没有用。看到这个后,我改用 guava-r09,效果很好。

        【讨论】:

          猜你喜欢
          • 2011-12-07
          • 1970-01-01
          • 2012-05-07
          • 1970-01-01
          • 1970-01-01
          • 2022-06-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多