Skip to content

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

@dmdum

Description

@dmdum

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: docsImprovement to the documentation for an API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions