0

我想在创建组时将成员添加到组中。我怎样才能做到这一点?

请求:

POST https://graph.microsoft.com/v1.0/groups
Content-Type: application/json

{
  "displayName": "displayName",
  "mailEnabled": true,
  "mailNickname": "mailNickname",
  "securityEnabled": false,
  "groupTypes": [
    "Unified"
  ],
  "members@odata.bind": [
    "https://graph.microsoft.com/v1.0/users/{userId}"
  ]
}

和代码:

Group group = new Group();

group.displayName = "displayName";  
group.mailEnabled = true;
group.mailNickname = "mailNickname";
group.securityEnabled = false;    
List<String> groupTypes = new ArrayList<>();
groupTypes.add("Unified");
group.groupTypes=groupTypes;
String userId = "userId";   

//HERE add members to group
//group.members=???

serviceClient.groups().buildRequest().post(group);

我应该如何以及在哪里编写“members@odata.bind”部分?

4

1 回答 1

0

指定成员的一种选择是构建自定义查询

JsonObject groupPayload = new JsonObject();
groupPayload.addProperty("displayName","<value>");
groupPayload.addProperty("mailNickname","<value>");
groupPayload.addProperty("mailEnabled",true);
groupPayload.addProperty("securityEnabled",false);
JsonArray groupTypes = new JsonArray();
groupTypes.add("Unified");
groupPayload.add("groupTypes",groupTypes);

//specify members
JsonArray members = new JsonArray();
members.add(String.format("https://graph.microsoft.com/v1.0/users/%s",userId));
groupPayload.add("members@odata.bind",members);

JsonObject response  = graphClient.customRequest("/groups").buildRequest().post(groupPayload).getAsJsonObject();
于 2019-02-20T17:34:40.647 回答