google-calendar-api icon indicating copy to clipboard operation
google-calendar-api copied to clipboard

refresh token

Open mangomi opened this issue 5 years ago • 3 comments

Hi, it was nice demo but let me know why you haven't used "google.client.user-authorization-uri" url. Because i just debug your code and found that only we are getting AccessToken but it will expire in an hour may be so definately we need refresh token as well.

mangomi avatar Jan 18 '20 13:01 mangomi

@mangomi Hey !

Do you have any idea how we can creatEvent based on the previously written code ?

Thank you very much

mohammedali-anis avatar May 28 '21 13:05 mohammedali-anis

how to hit api in post for Google calendar? and how we can set time in that

kaustubhkulkarni1995 avatar Dec 16 '21 09:12 kaustubhkulkarni1995

Hi, it was nice demo but let me know why you haven't used "google.client.user-authorization-uri" url. Because i just debug your code and found that only we are getting AccessToken but it will expire in an hour may be so definately we need refresh token as well.

Hi, I know it was long ago that u asked this, but today I had to implement this and here it goes.

Google only provide refresh token when u ask for offline accessType on your flow, so you gonna have to make ur authorize() function look like this:

private String authorize() throws Exception {
        AuthorizationCodeRequestUrl authorizationUrl;
        if (flow == null) {
            Details web = new Details();
            web.setClientId(clientId);
            web.setClientSecret(clientSecret);
            clientSecrets = new GoogleClientSecrets().setWeb(web);
            httpTransport = GoogleNetHttpTransport.newTrustedTransport();
            flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
                    Collections.singleton(CalendarScopes.CALENDAR))
                    .setAccessType("offline")
                    .build();
        }
        authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectURI);
        System.out.println("cal authorizationUrl->" + authorizationUrl);
        return authorizationUrl.build();
    }

Hope this helps someone looking for answers!

bryanwac avatar Sep 13 '24 21:09 bryanwac