Google 应用引擎更新用户信息出现错误 400 BAD_REQUEST

Google app-engine updating user information getting error 400 BAD_REQUEST

使用 Admin SDK 的目录 API 更新用户信息时出现错误:

400 BAD_REQUEST

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid Input: Bad request for ",
    "reason" : "invalid"
  } ],
  "message" : "Invalid Input: Bad request for "
}

正在尝试更新用户的组织详细信息字段,例如姓名、职位和部门

我的示例代码:`

Get users = directoryService.users().get(userEmail);
User user = users.execute();
try{
    List<UserOrganization> userOrg = new ArrayList<UserOrganization>();
    userOrg = user.getOrganizations();
    if(userOrg != null){
        UserOrganization f_userOrg = new UserOrganization();
        f_userOrg = userOrg.get(0);
     if(f_userOrg != null){
            f_userOrg.setTitle("SAP Asso");
            f_userOrg.setName("xyz company name");
            f_userOrg.setDepartment("xyz dept name");
            f_userOrg.setType("work");
            userOrg.add(f_userOrg);
            user.setOrganizations(userOrg);
        }
    }
    InputStream body =  directoryService.users().update(userEmail,user).executeAsInputStream();
// @ this line it throws exception 400 BAD_REQUEST 
}catch(Exception e){
        e.printStackTrace();
    }

我参考这个 update_user link 来更新用户数据。

任何帮助将不胜感激。 谢谢。

您可以打印发送给 Google API 的请求吗?您发送的格式可能有问题。

400 BAD_REQUEST is the request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

所以基本上 API 调用时参数不匹配。在这种情况下,您的请求会发送到服务器,但由于错误的请求参数,它会给出 400 错误。