Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh token #1

Open
mangomi opened this issue Jan 18, 2020 · 3 comments
Open

refresh token #1

mangomi opened this issue Jan 18, 2020 · 3 comments

Comments

@mangomi
Copy link

mangomi commented Jan 18, 2020

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.

@mohammedali-anis
Copy link

@mangomi Hey !

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

Thank you very much

@kaustubhkulkarni1995
Copy link

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

@bryanwac
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants