user381878
user381878

Reputation: 1539

Unable to run google gdata api for google docs

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)

Upvotes: 2

Views: 2422

Answers (3)

Ryan
Ryan

Reputation: 2008

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.

Upvotes: 0

Canonical Chris
Canonical Chris

Reputation: 109

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 the DocumentList and DocumentList exception classes from the example.

If you do so that reduces the above example to:

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());
    }
    }
}   

That example worked for me (with the r09 guava JAR).

Tracing this example suggests that the generated URL is

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

Upvotes: 3

Canonical Chris
Canonical Chris

Reputation: 109

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.

Upvotes: 0

Related Questions