Hi
I am new at using the OAuth process. I am using the 2 legged process
to get the OAuth done.
I am getting the following exception. This error has really wasted my
two days. Please help me out.
com.google.gdata.util.AuthenticationException: Token invalid - Invalid
AuthSub token.
<HTML>
<HEAD>
<TITLE>Token invalid - Invalid AuthSub token.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - Invalid AuthSub token.</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
at
com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:
600)
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.getEntry(Service.java:1352)
at com.google.gdata.client.GoogleService.getEntry(GoogleService.java:
567)
at com.google.gdata.client.Service.getEntry(Service.java:1278)
at
com.google.gdata.data.spreadsheet.SpreadsheetEntry.getDefaultWorksheet(SpreadsheetEntry.java:
143)
I am using the 2legged OAuth process to authenticate the DocsService
and SpreadsheetService.
My code snippet is
DocsService client = new DocsService("yourCo-yourAppName-v1");
SpreadsheetService service = new SpreadsheetService("yourCo-
yourAppName-v1");
String CONSUMER_KEY = "THE_CONSUMER_KEY";
String CONSUMER_SECRET = "THE_SECRET_KEY";
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setOAuthType(OAuthParameters.OAuthType.TWO_LEGGED_OAUTH);
try {
client.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());
service.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());
} catch (OAuthException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Now i am able to retrieve the spreadsheet for a particular user using
the code below
// let us assume my username is
x...@mydomain.com
URL feedUrl = new URL("
https://spreadsheets.google.com/feeds/
spreadsheets/private/full" +
"?"+XOAUTH_REQUESTOR_ID+"=" + username);
SpreadsheetFeed feed = service.getFeed(feedUrl ,
SpreadsheetFeed.class);
List<com.google.gdata.data.spreadsheet.SpreadsheetEntry> spreadsheets
= feed.getEntries();
for (com.google.gdata.data.spreadsheet.SpreadsheetEntry entry :
spreadsheets ) {
System.out.println(entry.getTitle().getPlainText());
}
But now when i try to retrieve the default worksheet of any
spreadsheet obtained above using the code
WorksheetEntry defaultWorksheet =
spreadsheetEntry.getDefaultWorksheet();
I get the exception defined above.
If for the time being i remove the code of retrieving the default
spreadsheet(to avoid the exception i got above), and try to get the
cell feed as described below :
String key = spreadsheetEntry.getKey() ;
FeedURLFactory urlFactory = FeedURLFactory.getDefault();
URL cellFeedUrl = urlFactory.getCellFeedUrl(key, "od6", "private",
"full");
CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
then i get the following exception:
com.google.gdata.util.AuthenticationException: Unauthorized
<HTML>
<HEAD>
<TITLE>Unknown authorization header</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unknown authorization header</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
at
com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:
600)
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)