I am building a simple Java app that talks to the Google Directory API to add and remove users from groups in my Google Workspace. I have build the client like this:
InputStream inputStream = NewsletterSubscriber.class.getResourceAsStream("/credentials.json");
if (inputStream == null) {
throw new FileNotFoundException(
"The credentials file could not be found"
);
}
GoogleCredentials googleCredentials = GoogleCredentials
.fromStream(inputStream)
.createScoped(DirectoryScopes.ADMIN_DIRECTORY_GROUP_MEMBER);
HttpCredentialsAdapter httpRequestInitializer = new HttpCredentialsAdapter(googleCredentials);
DIRECTORY = new Directory.Builder(
new NetHttpTransport(),
GsonFactory.getDefaultInstance(),
httpRequestInitializer
)
.setApplicationName("Whatever")
.build();
Member member = new Member()
.setEmail("someone@whatever.com")
.setRole("MEMBER");
Directory.Members.Insert insert = DIRECTORY.members().insert(
"newsletter@whatever.com",
member
);
int statusCode = insert.getLastStatusCode();
String statusMessage = insert.getLastStatusMessage();
When I run this code, statusCode is always -1 and statusMessage is always null. The Google Developer Console shows no activity on the service account being used.
So in short, I have no idea what's happening.
How can I debug what the Google client is doing? I can't seem to find any kind of logging/debugging/tracing options in the Google Java SDK. I'm sure I'm missing something simple, but I can't for the life of me figure out what.