I am using the service account model and Google's Java API to retrieve and modify users.
I am able to successfully create a GoogleCredential object using code similar to Google's example:
GoogleCredential googleCredential = new GoogleCredentialBuilder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setServiceAccountId(SERVICE_ACCOUNT_EMAIL) .setServiceAccountUser(SERVICE_ACCOUNT_USER) .setServiceAccountPrivateKeyFromP12File(P12_PRIVATE_KEY_FILE) .setServiceAccountScopes(Collections.singleton(GLOBAL_USER_AND_ALIAS_SCOPE) .build();
I see no mention in any examples that I have to explicitly create an access token, so I have been assuming that the above code takes care of that. Is that true?
After that, I successfully create an instance of Directory, then try to retrieve a specific user:
User user = new User(); user = directory.users().get(uid).execute();
That fails, throwing a NullPointerException.
When I inspect the GoogleCredential object right before the call to get the user object, it appears that it does not contain an access token:
accessToken = null refreshToken = null
What am I missing?
How does one get the access token using the service account model?
Thanks in advance.