【发布时间】:2014-08-11 06:06:22
【问题描述】:
我正在尝试使用 Google admin sdk 创建用户。但是,我不断收到以下异常:Invalid Given/Family Name: 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"
}
我真的不明白我错过了什么或做错了什么。
【问题讨论】:
-
似乎是一个相当明确的错误信息。你能显示你的 userObject 字符串吗?
-
您好,userObject 字符串在更新后的帖子中。谢谢
标签: java google-admin-sdk