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

How do I use the accessToken given after a user gives the app permissions? #1103

Open
dmdum opened this issue Nov 22, 2022 · 1 comment
Open

Comments

@dmdum
Copy link

dmdum commented Nov 22, 2022

I'm taking over this feature that creates an event on a user's calendar. Our system was previously able to do this using com.google.api.client.googleapis.auth.oauth2.GoogleCredential, but since that's been deprecated, I'm looking for another way to replicate this feature.

This is how we previously did it (on groovy):

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.services.calendar.Calendar
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.jackson2.JacksonFactory
import com.google.api.services.calendar.model.Event

. . .

GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken)
Calendar service = new Calendar.Builder(
    GoogleNetHttpTransport.newTrustedTransport(),
    JacksonFactory.getDefaultInstance(),
    credential)
    .setApplicationName("applicationName")
    .build();
    
Event event = new Event()

. . .
service.events().insert("primary", event).execute()

With the com.google.api.client.googleapis.auth.oauth2.GoogleCredential deprecated, would it be correct to assume that the com.google.auth.oauth2.GoogleCredentials will be taking its place?

I tried using the new .GoogleCredentials (we're now in java) but I can't seem to re-use the same code flow in the previous implementation since the 3rd argument requires an httRequestInitializer

Is there another way to use the accessToken given after a user gives the app permissions? I'd like to lessen the changes in the code as much as possible.

@DineshSolanki
Copy link

I would appreciate having an example to retrieve the User's email with the same
earlier I was using following code

GoogleCredential credential = new GoogleCredential().setAccessToken(token);
 Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new GsonFactory(), credential)
                .setApplicationName("Oauth2")
                .build();
UserInfo  userinfo = oauth2.userinfo().get().execute();

whats the correct way after GoogleCredential deprecation

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

2 participants