0

This is how I create my GoogleAuthorizationCodeFlow

        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource("credentials.oauth-credentials").getFile());
        return new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
                clientId, clientSecret, SCOPES)             
                .setDataStoreFactory(new FileDataStoreFactory(file))
                .setAccessType("offline")
                .build();

then after authorizing the user in Google and redirect back to my site, I save the credentials to the credential store by doing this

flow.createAndStoreCredential(tokenResponse, userId);

Then I open my credentials.oauth-credentials file (located in my classpath). I expect it to contain the credentials that I just saved, but this file is empty. May I know why?

Also, I tried shutting down my app after I saved a credential then starting up my app again. Now the credential store says that the credentials saved earlier does not exist. It's like when my app is restarted, the credential store resets itself. Why is this happening?

  • FileDataStoreFactory(File dataDirectory) Takes a directory not a file. And remember where ever you are hosting this needs to have permission to write to that directory. – Linda Lawton - DaImTo Jun 04 '20 at 11:34
  • @DaImTo so here's a way to create a data store factory that I found `private static final java.io.File DATA_STORE_DIR = new java.io.File(System.getProperty("user.home"), ".store/adsense_host_sample");` I have no idea what this means – Michael Jackson Jun 05 '20 at 04:53

0 Answers0