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

opikeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
think you still need to get a token, will check and get back to you
0
abhuvanCommented:
0
Mick BarryJava DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.