如何使用Java更新用户的externalId [英] How to update a user's externalId using Java

查看:260
本文介绍了如何使用Java更新用户的externalId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用基于Google Admin SDK文档的externalId更新用户。

I'm trying to update a user with an externalId based on the Google Admin SDK documentation.

UserExternalId externalId = new UserExternalId();
    externalId.setType( "account" );
    externalId.setValue( "test" );
    User user = new User();
    user.setExternalIds( externalId );
    try {
        User update = directory.users().update( "USERKEY", user ).execute().setExternalIds( externalId );
        LOGGER.info("Response from google: " + update.toPrettyString());
        User full = directory.users().get( "USERKEY" ).setProjection( "full" ).execute();
        LOGGER.info( "Response from new get user: " + full.toPrettyString() );
    } catch (IOException e) {
        LOGGER.info("Error: " + e);
    }

在更新调用上记录响应时,我可以看到externalId已填写并且不会抛出任何错误。当我尝试获得相同的用户时,没有externalId的痕迹。

When logging the response on the update call I can see that externalId is filled in and no errors are thrown. When I try to get the same user there is no trace of the externalId.

当我使用Google' API资源管理器并填写ExternalId,我得到相同的行为。看起来Google API正在接受更新请求,但忽略了ExternalId。将externalId添加到用户的正确方法是什么?

When I use Google' APIs explorer and fill in the ExternalId there I get the same behavior. It looks like the Google API is accepting the update request but is ignoring the ExternalId. What is the correct way to add an externalId to a user?

编辑:

SGC的回答帮助了我。 setExternalIds方法需要一个ExternalIds列表,我忘了这样做。 Google Java Directory API似乎在获取externalIds时返回一个json对象,因此需要对其进行解析才能读取它。

SGC's answer helped me out. The setExternalIds method expects a list of ExternalIds, I forgot to do this. The Google Java Directory API seems to return a json object when fetching externalIds, so it is necessary to parse it to read it.

推荐答案

更新用户的外部标识时,如果未正确设置JSON,则不会保存(尽管它会给出200响应)。如果您尝试向此用户发送get请求,则在响应中看不到更新的值。

When updating external id of user, if the JSON is not set properly, it won't be saved(though it gives 200 response). If you try to send get request on this user, then the updated value is not seen in the response.

尝试使用 Oauth Play Ground 发送请求

我尝试在Users.update请求中使用{externalIds:[{value:shaggynetwork,type:network}]} 。在Users.get中,响应是:

I tried using {"externalIds":[{"value":"shaggynetwork","type":"network"}]} in "Users.update" request. And in the "Users.get", the response is:

HTTP/1.1 200 OK
Content-type: application/json; charset=UTF-8
{
  "externalIds": [
   {
     "type": "network", 
      "value": "shaggynetwork"
}

],

步骤:


  1. 点击 https://developers.google.com/oauthplayground/

在步骤1中,授权API的左侧在空白处给出 https://www.googleapis.com/auth/admin.directory.user ,然后点击授权API。

In the step 1, on the left side of "Authorize APIs" in the blank give https://www.googleapis.com/auth/admin.directory.user, then click on "Authorize APIs".

3.在第2步中,点击交换令牌代码

3.In step 2, click on "exchange code for tokens"


  1. 在步骤3中,选择HTTP方法:PUT,给出请求URI值: https://www.googleapis.com/admin/directory/v1/users/userKey(giver userkey value)。

  1. In step 3, select HTTP method:PUT, give request URI value:https://www.googleapis.com/admin/directory/v1/users/userKey(giver userkey value).



< 5.点击输入请求体,构建json:

5.click on "enter request body", build json:

{externalIds:[{value:shaggynetwork,type:网络}]}

{"externalIds":[{"value":"shaggynetwork","type":"network"}]}

6.点击发送请求。

在文档中,不清楚关于如何更新外部ID。

In documentation, its not clear on how to update external id.

如果您需要任何帮助,请告诉我。

Let me know if you need any help on this.

这篇关于如何使用Java更新用户的externalId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆