Have created a project from google developer console and created a service account. Downloaded the key store. I need to use google admin sdk to create/delete/access users. I see the Admin SDK ON APIs&Auth->API. Not able to get authorized due to scope errors.
Sample Java Snippet
public boolean makeConnectionWithGoogleAPI(){
try{
List<String> scopes = Arrays.asList("https://www.googleapis.com/auth/admin.directory.user",
"https://www.googleapis.com/auth/admin.directory.user.readonly");
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(clientEmail)
.setServiceAccountUser(userId)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(privateKeyStoreLocation))
.build();
Directory admin =
new Directory.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
Directory.Users.List list = admin.users().list();
Users users = list.execute();
List<User> listUsers=users.getUsers();
for(User user:listUsers){
System.out.println(user.getId());
}
return true;
}catch(Exception e){
e.printStackTrace();
}
return false;
}
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request { "error" : "access_denied", "error_description" : "Requested scopes not allowed: https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/admin.directory.user.readonly" } at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)