无法为 google 文档运行 google gdata api
我对 google 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)
I have been so frustated by google API. Everytime I try, its just doesn't work even after collecting tons of jars from here and there. I would be really grateful if anyone can help me with the below piece of code ->
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();
}
}
}
I have added following jar files in the classpath:
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
Error I am getting is:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 URL 是问题所在——请参阅下文了解更多详细信息。
我认为最好从 gdata/java/sample/docs 中的示例代码开始,并从例子。
如果你这样做,上面的例子就会简化为:
这个例子对我有用(使用 r09 guava JAR)。
跟踪这个例子表明生成的 URL 是
I think the URL is the problem is the URL--see below for more details.
I think it is better to start from the sample code in
gdata/java/sample/docs
and take theDocumentList
andDocumentList
exception classes from the example.If you do so that reduces the above example to:
That example worked for me (with the r09 guava JAR).
Tracing this example suggests that the generated URL is
是的,我也已经走到了这一步。我想知道这个问题是否与 Guava 库有关 - 我尝试了 Guava 11,但他们在 2011 年 10 月(即当前的 gdata 版本(2011 年 9 月)之后)取消了 ImmutableSet.of(Object[] objs) 调用。
我的第一个怀疑是 URL……这就是我现在正在尝试的。
Yeah, that's how far I got too. I wonder if the problem has something to do with the Guava library--I tried Guava 11, but they took out the ImmutableSet.of(Object[] objs) call in October 2011, after the current gdata release (Sept 2011).
My first suspicion would be the URL ... that is what I am trying right now.
我想为可能遇到与我相同问题的其他人添加一条注释:
网址很好,但我使用的是 guava-11.0.1,尝试了 guava-11.0.2,尝试了 guava-14,但没有他们中的一些人工作了。看到这个之后我改用 guava-r09 并且效果很好。
I would like to add one note for others who may have had the same problem that I had:
The web address was just fine, but I was using guava-11.0.1, tried guava-11.0.2, tried guava-14 and none of them worked. After seeing this I instead used guava-r09 and it worked great.