Hello Dmitri,
You are getting an OAuth 2.0 token for the Tasks API and are using the same
token to access the Calendar API using the OAuth 1.0 protocol. The error is
expected as those tokens are not compatible.
If you want to use the OAuth 2.0 token from the Tasks API to access Calendar
data, you can do something like this:
service.setHeader("Authorization", "OAuth " + this.oauthAccessToken);
Please, do not forget to ask the Calendar API scope when requesting the
OAuth 2.0 token:
String scope = "https://www.googleapis.com/auth/tasks
https://www.google.com/calendar/feeds";
However, you will have to handle the "token expired" exception and refresh
the token manually as the Google Data client library doesn't natively
support OAuth 2.0.
One last thing, please use SSL (https) over non-SSL (http) whenever possible
for accessing Google APIs.
Best,
Alain
On Fri, Jul 1, 2011 at 1:46 PM, DP <[email protected]> wrote:
> Hello!
>
> Can the cause of the problem be that I attempt to access two different
> Google services (Tasks and Calendar) with different scopes using ONE
> access token?
>
> TIA
>
> Dmitri
>
> On Jul 1, 5:47 pm, DP <[email protected]> wrote:
> > Hello!
> >
> > I get the error
> >
> > com.google.gdata.util.AuthenticationException: Unknown authorization
> > header
> > at
> >
> com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:
> > 600) ~[gdata-core-1.0.jar:na]
> > at
> >
> com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:
> > 563) ~[gdata-core-1.0.jar:na]
> > at
> >
> com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:
> > 552) ~[gdata-core-1.0.jar:na]
> > at
> >
> com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:
> > 530) ~[gdata-core-1.0.jar:na]
> > at
> >
> com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:
> > 535) ~[gdata-core-1.0.jar:na]
> >
> > when trying to access the Google Calendar data via their API.
> >
> > Here is what happens before that error.
> >
> > 1) I authenticate with Google:
> >
> > final AccessTokenResponse response =
> > new GoogleAuthorizationCodeGrant(httpTransport,
> > jsonFactory,
> > clientId, clientSecret, authorizationCode,
> > redirectUrl).execute();
> >
> > final GoogleAccessProtectedResource accessProtectedResource =
> > new GoogleAccessProtectedResource(
> > response.accessToken, httpTransport, jsonFactory,
> > clientId, clientSecret,
> > response.refreshToken);
> >
> > LOGGER.debug("response.accessToken: {}", response.accessToken);
> >
> > this.oauthAccessToken = response.accessToken;
> >
> > ...
> >
> > 2) I read some data via the tasks API:
> >
> > this.service =
> > new Tasks(httpTransport, accessProtectedResource,
> > jsonFactory);
> > this.service.setApplicationName(this.applicationName);
> >
> > This seems to work.
> >
> > 3) Then I try to read data from the Google Calendar API:
> > final OAuthHmacSha1Signer signer = new
> > OAuthHmacSha1Signer();
> >
> > final GoogleOAuthParameters oauth = new
> > GoogleOAuthParameters ();
> >
> > oauth.setOAuthConsumerKey("myapp.com");
> > oauth.setOAuthConsumerSecret(CLIENT_SECRET); // Client
> > secret from "Google API access" page, "Client secret" entry
> > oauth.setOAuthToken(this.oauthAccessToken); // Access
> > token from step 1
> > oauth.setOAuthTokenSecret(aAuthorizationCode);
> > // aAuthorizationCode is taken from the callback URL.
> > // Forhttp://
> myapp.com/oauth2callback?code=4/uy8Arb4bhRPwWYSr3QwKPt9lIZkt
> > // aAuthorizationCode is equal to "4/
> > uy8Arb4bhRPwWYSr3QwKPt9lIZkt" (without quotes)
> >
> > oauth.setScope(SCOPE_CALENDAR); //
> https://www.google.com/calendar/feeds/
> >
> > final CalendarService calendarService =
> > new CalendarService(APPLICATION_NAME);
> >
> > calendarService
> > .setOAuthCredentials(oauth, signer);
> >
> > LOGGER.debug("calendarService: {}", calendarService);
> >
> > final URL feedUrl =
> > new URL(
> > "http://www.google.com/calendar/feeds/
> > default/allcalendars/full");
> > final CalendarFeed resultFeed =
> > calendarService.getFeed(feedUrl,
> > CalendarFeed.class);
> >
> > At the last line (calendarService.getFeed...) the aforementioned
> > exception occurs.
> >
> > I have following questions:
> >
> > 1) Is my call
> >
> > oauth.setOAuthConsumerKey
> >
> > correct?
> >
> > I. e. is the "consumer key" equal to "Product name" in the Google API
> > console, or to "Client ID" field (value is something like
> > 42912397129473.apps.googleusercontent.com)
> >
> > 2) Is the setOAuthTokenSecret correct? I. e. is it the code that I
> > get, when Google redirects the user back to my app?
> >
> > 3) If questions 2 and 3 were answered with yes, what else can be the
> > cause of my problem?
> >
> > Thanks
> >
> > Dmitri
> >
> > P. S.: Previously, I could access Google calendar with simple access
> > (i. e. with Google user name and password). However, this is not an
> > option now because users of my app will not want to give away their
> > Google password.
> >
> > P. P. S.: You can earn StackOverflow reputation points by answering
> > the question there:
> http://stackoverflow.com/questions/6550143/google-calendar-api-and-oa...
>
> --
> You received this message because you are subscribed to the Google
> Groups "Google Calendar Data API" group.
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://code.google.com/apis/calendar/community/forum.html
>
--
Alain Vongsouvanh
--
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html