Java 无法创建用户-400错误请求。。。谷歌服务帐户
我正在尝试使用GoogleAdminSDK创建一个用户。但是,我不断遇到以下异常:无效的给定/姓氏:FamilyName。到目前为止,这是我的代码:Java 无法创建用户-400错误请求。。。谷歌服务帐户,java,google-admin-sdk,Java,Google Admin Sdk,我正在尝试使用GoogleAdminSDK创建一个用户。但是,我不断遇到以下异常:无效的给定/姓氏:FamilyName。到目前为止,这是我的代码: private PostMethod performPostRequest(Connection con, String url, String userObject)
private PostMethod performPostRequest(Connection con,
String url,
String userObject)
throws Exception {
HttpClient httpClient = new HttpClient();
PostMethod post = null;
for (int i = 0; i < 2; i++) {
LOG.info(SCHEDULER_LOG_INVOKING + url + SCHEDULER_LOG_LINE_FEED);
post = new PostMethod(url);
String accessToken = mDaoService.getSetting(con, GoogleSettings.TOKEN);
post.addRequestHeader(HTTP_HEADER_AUTHORIZATION, HTTP_HEADER_BEARER + accessToken);
if (userObject != null) {
post.setRequestEntity(new StringRequestEntity(userObject));
}
else {
throw new Exception("Entity is null");
}
int errorCode = httpClient.executeMethod(post);
if (errorCode == HttpStatus.SC_CREATED) {
break;
}
}
if (post == null) {
throw new Exception("Post object is null");
}
return post;
}
我真的不明白我遗漏了什么或做了什么不正确。在最初的问题之后的一段时间,但如果这对其他人有帮助的话-我也有这个问题,但通过添加ContentType头(Content-Type:application/json)解决了它。似乎是一条非常明确的错误消息。你能显示你的用户对象字符串吗?嗨,用户对象字符串在更新的帖子中。谢谢
{
"primaryEmail": "saurabh@doamin.com",
"name": {
"givenName": "Mike",
"familyName": "tyson"
},
"password": "hello"
}