我正在尝试使用Google管理员sdk创建用户。但是,我继续获得以下异常:无效的给定/姓氏:FamilyName 。这是我的代码到目前为止:
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;
}
我的用户对象是JSON格式 例如:
{
"primaryEmail": "saurabh@doamin.com",
"name": {
"givenName": "Mike",
"familyName": "tyson"
},
"password": "hello"
}
我真的不明白我错过了什么或做错了什么。
答案 0 :(得分:0)
在原始问题之后的某个时间,但是如果这有助于其他任何人 - 我也有这个问题,但是通过添加ContentType标头解决了它(Content-Type:application / json)