I'm trying use the Google Directory API. In my project I enabled the Admin SDK, Google+ Domains API.
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
ArrayList<String> scopeList = new ArrayList<>();
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_USER);
scopeList.add(DirectoryScopes.ADMIN_DIRECTORY_USER_READONLY);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("[email protected]")
.setServiceAccountScopes(scopeList)
.setServiceAccountPrivateKeyFromP12File(new File("c:/my-file.p12"))
.setServiceAccountUser("logined-user-email")
.build();
credential.setAccessToken(<accessToken from OAuth to google>);
Directory admin = new Directory.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName("Test")
.setHttpRequestInitializer(credential).build();
Users users = admin.users().list().setDomain("my-domain.com").execute();
=> "Domain cannot use apis"
Where is my error?