Java 无法为google文档运行google gdata api
谷歌API让我非常失望。每次我尝试,它就是不工作,即使收集吨罐从这里和那里。如果有人能帮我完成下面的代码,我将不胜感激->Java 无法为google文档运行google gdata api,java,gdata,gdata-api,Java,Gdata,Gdata Api,谷歌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 clas
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)
com.google.gdata.util.ResourceNotFoundException:未找到
找不到
找不到
错误404
位于com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:591)
位于com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
位于com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
位于com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
位于com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
位于com.google.gdata.client.Service.getFeed(Service.java:1135)
位于com.google.gdata.client.Service.getFeed(Service.java:998)
位于com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
位于com.google.gdata.client.Service.getFeed(Service.java:1017)
位于com.javainsight.cloud.TestGoogleDocs.main(TestGoogleDocs.java:21)
是的,我也走了这么远。我想知道这个问题是否与Guava库有关——我尝试了Guava 11,但在当前gdata发布(2011年9月)之后,他们在2011年10月取消了ImmutableSet.of(Object[]objs)调用
我的第一个怀疑是URL。。。这就是我现在正在尝试的。我认为URL是问题所在,URL是问题所在--请参阅下面的详细信息 我认为最好从
gdata/java/sample/docs
中的示例代码开始,并从示例中获取DocumentList
和DocumentList
异常类
如果这样做,则将上述示例简化为:
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番石榴罐)
跟踪此示例表明生成的URL是
"https://docs.google.com/feeds/default/private/full"
我想为可能与我有相同问题的其他人补充一点: 网址还不错,但我用的是guava-11.0.1,试过guava-11.0.2,试过guava-14,都没用。看到这个之后,我用了番石榴-r09,效果非常好