【问题标题】:Unable to create a user - 400 bad Request... Google service account无法创建用户 - 400 bad Request... Google 服务帐户
【发布时间】: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


【解决方案1】:

在最初的问题之后的一段时间,但如果这对其他人有帮助 - 我也遇到了这个问题,但通过添加 ContentType 标头(Content-Type:application/json)解决了它

【讨论】:

    猜你喜欢
    • 2021-09-30
    • 2022-11-08
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多