• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1443
  • Last Modified:

Receiving error in google docs java api: com.google.gdata.util.AuthenticationException: Token invalid

Trying to create a simple example that connects to google docs. At this line:

DocumentListFeed feed = myService.getFeed(query, DocumentListFeed.class);

I get the following error message:

com.google.gdata.util.AuthenticationException: Token invalid
<HTML>
<HEAD>
<TITLE>Token invalid</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

        at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(Ht
pGDataRequest.java:508)
        at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(
oogleGDataRequest.java:555)
        at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDat
Request.java:480)

I double and triple checked that the user credentials specified were correct.
SpreadsheetService myService = new SpreadsheetService("exampleCo-exampleApp-1");
	  System.out.println("After new spreadsheetservice");
		myService.setUserCredentials("XXXXXXX@gmail.com", "XXXXXXX");
		System.out.println("After setusercredentials");
		URL feedUri = new URL("http://docs.google.com/feeds/documents/private/full/");
		System.out.println("After new URL");
		com.google.gdata.client.DocumentQuery query = new DocumentQuery(feedUri);
		System.out.println("After new DocumentQuery");
		//query.setSortMode("title");
		query.setTitleQuery("DOW PE");
		query.setTitleExact(true);
		query.setMaxResults(10);
		System.out.println("After setMaxResults");
		DocumentListFeed feed = myService.getFeed(query, DocumentListFeed.class);
		System.out.println("After getFeed");

Open in new window

0
opike
Asked:
opike
  • 2
3 Solutions
 
objectsCommented:
think you still need to get a token, will check and get back to you
0
 
abhuvanCommented:
0
 
objectsCommented:
0
 
opikeAuthor Commented:
I just figured out the problem... which essentially was that I mixed code for spreadsheets and documents (i.e. word processing documents). I was initially authenticating for spreadsheets but then tried to do a search against documents. I've attached a code snippet that actually works.
FeedURLFactory factory;
		
factory = FeedURLFactory.getDefault();
//The service name info being passed is for google's tracking purposes
SpreadsheetService myService = new SpreadsheetService("exampleCo-exampleApp-1");
System.out.println("After new spreadsheetservice");
		myService.setUserCredentials("hastapasta99@gmail.com", "madmax1.");
System.out.println("After setusercredentials");
URL feedUri = new URL("http://spreadsheets.google.com/feeds/spreadsheets/private/full/");
System.out.println("After new URL");
com.google.gdata.client.DocumentQuery query = new DocumentQuery(feedUri);
System.out.println("After new DocumentQuery");
//query.setSortMode("title");
query.setTitleQuery("DOW PE");
query.setTitleExact(true);
query.setMaxResults(10);
System.out.println("After setMaxResults");
SpreadsheetFeed feed2 = myService.getFeed(query, SpreadsheetFeed.class);
System.out.println("After getFeed");

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now