Hello!

Thanks for your answer.

> Please use "https://www.google.com/calendar/feeds"; as scope.

I modified the code accordingly.

>             oauthParameters.setOAuthVerifier("toy8IMW6sInKDTjPxfy5zMFD");
>
>             
oauthParameters.setOAuthToken("4/Oj-Q3isN3rz8mvJbgAkaIHGkL882");
>             
oauthParameters.setOAuthTokenSecret("xQ8-9M22ZSdITuaTFAhPpcoA");
>


> Are those hard-coded or retrieved from the OAuth dance?

They are retrieved from the OAuth dance. At the moment, I just paste these 
values from the log output of the web application.

>             oauthHelper.getAccessToken(oauthParameters);
>


> Are you executing this code every time? You should do it only once to 
retrieve the long-lived Access Token.

Then, my entire process is wrong. I assumed that 

a) the access token is short lived and
b) the refresh token is long lived,

i. e. I should get the refresh token once and exchange it for access tokens 
often (as in Google Tasks API).

Now it seems that it's exactly the opposite - it's necessary to get the 
access token once and then use it as many times as I want (until the user or 
my app revoke it).

* * *

I changed my code:

1) In the interactive part, I get the access token at the end of OAuth 
dance.

> try {
>     final String accessToken = 
oauthHelper.getAccessToken(oauthParameters);
>    
>     LOGGER.debug("Access token: {}", accessToken);
> } catch (final OAuthException exception) {
>     LOGGER.error("", exception);
> }
> 

2) Then, in the server-sided part, I use the OAuth parameters in this way:


> @Test
> public void testCalendar2() {
>     try {
>         final PrivateKey privKey = getPrivateKey();
>         final OAuthRsaSha1Signer signer = new OAuthRsaSha1Signer(privKey);
>
>        
>         GoogleOAuthParameters oauthParameters = new 
GoogleOAuthParameters();
>         oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
>
>         oauthParameters.setScope("https://www.google.com/calendar/feeds";);
>
>         oauthParameters.setOAuthVerifier("Mbu7axn2kpiVsvoQmh18Q21f"); // 
Verifier from the interactive part
>        
>         
oauthParameters.setOAuthToken("1/Pw10CRNNfiHMdk9n4U3FHP8pccHuF17VsicKYK8xt4Y"); 
// Access token from the interactive part
>         oauthParameters.setOAuthTokenSecret("ftepxc4olAgTGVmXJhjS7HLo"); 
// Token secret from the interactive part
>
>         final CalendarService calendarService =
>                 new CalendarService("myapp.com");
>
>         calendarService
>                 .setOAuthCredentials(oauthParameters, signer);
>        
>         LOGGER.debug("calendarService: {}", calendarService);
>
>         final URL feedUrl =
>                 new URL(
>                         
"https://www.google.com/calendar/feeds/default/allcalendars/full";);
>         final CalendarFeed resultFeed =
>                 calendarService.getFeed(feedUrl, CalendarFeed.class);
>
>         LOGGER.debug("resultFeed: {}", resultFeed);
>
>         LOGGER.debug("Your calendars:");
>
>         CalendarEntry pccCalendar = null;
>         for (int i = 0; (i < resultFeed.getEntries().size())
>                 && (pccCalendar == null); i++) {
>             final CalendarEntry entry = resultFeed.getEntries().get(i);
>            
>             LOGGER.debug(entry.getTitle().getPlainText());
>         }
>
>     } catch (final IOException exception) {
>         LOGGER.error("", exception);
>         Assert.fail(exception.getMessage());
>     } catch (final OAuthException exception) {
>         LOGGER.error("", exception);
>         Assert.fail(exception.getMessage());
>     } catch (final ServiceException exception) {
>         LOGGER.error("", exception);
>         Assert.fail(exception.getMessage());
>     }
> }
> 


And now it seems to work.

Best regards

Dmitri

-- 
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

Reply via email to