我正在尝试使用以下代码通过 Google Directory API 创建一个新用户帐户。我得到的结果是密码无效。什么密码?我下载的 P12 文件有问题吗?
Collection<String> SCOPE = Arrays.asList("https://www.googleapis.com/auth/admin.directory.user");
String serviceAcctEmailAddress = "xxx@developer.gserviceaccount.com";
String serviceAcctUser = "admin@x.com";
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("x@x.com");
u.setName(un);
u.setPassword("Axxx1234");
u.setHashFunction("SHA-1");
u.setPrimaryEmail("x@x.com");
u.setSuspended(false);
u.setAgreedToTerms(true);
Directory.Users.Insert addUser = directory.users().insert(u);
addUser.execute();
收到以下错误:
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)
感谢您对入门的任何帮助!