Following code is same from PlusService Account Sample and I have modified it for Directory API, created new test user, assigned id and password, it returns empty {} instead of returning user test
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Collections.singleton( DirectoryScopes.ADMIN_DIRECTORY_USER))
.setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
.setServiceAccountUser("[email protected]")
.build();
// set up global Plus instance
plus = new Plus.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
dir = new Directory.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName("some name").build();
User test= new User();
test.setCustomerId("1");
test.setPassword("sdfsdf");
dir.users().insert(test).execute();
System.out.print("Return test"+dir.users().list().toString());