I want to use the Gmail Java API with an existing access token and refresh token with the following code:
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singletonList(GmailScopes.GMAIL_READONLY))
.setAccessType("offline")
.setCredentialDataStore()
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
I need to create a DataStore of StoredCredential object, set the tokens there and pass it to setCredentialDataStore method. I understand this can be done somehow by using MemoryDataStoreFactory.
Does anyone know how can I do it?