I'm trying to create a new user account via the Google Directory API using the code below. The result I get back is invalid password. What password? Problem with the P12 file I downloaded?
Collection<String> SCOPE = Arrays.asList("https://www.googleapis.com/auth/admin.directory.user");
String serviceAcctEmailAddress = "[email protected]";
String serviceAcctUser = "[email protected]";
final HttpTransport TRANSPORT = new NetHttpTransport();
final JsonFactory JSON_FACTORY = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAcctEmailAddress)
.setServiceAccountUser(serviceAcctUser)
.setServiceAccountScopes(SCOPE)
.setServiceAccountPrivateKeyFromP12File(new File("1fc6.p12"))
.build();
Directory directory = new Directory.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("API-Project")
.build();
// create user object
User u = new User();
UserName un = new UserName();
un.setGivenName(".");
un.setFamilyName("[email protected]");
u.setName(un);
u.setPassword("Axxx1234");
u.setHashFunction("SHA-1");
u.setPrimaryEmail("[email protected]");
u.setSuspended(false);
u.setAgreedToTerms(true);
Directory.Users.Insert addUser = directory.users().insert(u);
addUser.execute();
Getting the below error:
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Password",
"reason" : "invalid"
} ],
"message" : "Invalid Password"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
Thanks for any helping getting started!
Confirm the password you set for the user meets your domain's password policy.