1

我正在尝试使用 java 中的 micorosoft graph API 将用户添加到 Outlook 中的组。我已参考https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/group_post_members 添加用户。

然而,为了实现这一点,我正在使用microsoft graph java sdk,我需要在 java 的组中添加带有成员ID的json对象。

请让我知道如何在 java 中的请求正文中添加 json 对象。

我的代码如下所示:

    public void addMemberToGroup(String groupId,String userId) 
{
    final List<Option> options = new LinkedList<Option>();
    Group group =  mGraphServiceClient
                                      .groups(groupId)
                                      .buildRequest()
                                      .get();

    mGraphServiceClient
                        .groups(groupId)
                        .members(userId)
                        .buildRequest()
                        .post(group, 
                               /*add json in body*/
                              );

请让我知道如何在正文中添加数据,如下所示

    {
      "@odata.id": "https://graph.microsoft.com/v1.0/users/{userId}"
    }
4

1 回答 1

0

这里是高水平。

            // ============================================================
        // Create Service Principal

        ServicePrincipal servicePrincipal = authenticated.servicePrincipals().define(servicePrincipalName)
                .withNewApplication("http://" + servicePrincipalName)
                .create();
        // wait till service principal created and propagated
        SdkContext.sleep(15000);
        System.out.println("Created Service Principal:");
        Utils.print(servicePrincipal);
        spId = servicePrincipal.id();

        // ============================================================
        // Assign role to Service Principal

        RoleAssignment roleAssignment2 = authenticated.roleAssignments()
                .define(raName2)
                .forServicePrincipal(servicePrincipal)
                .withBuiltInRole(BuiltInRole.CONTRIBUTOR)
                .withSubscriptionScope(defaultSubscription)
                .create();
        System.out.println("Created Role Assignment:");
        Utils.print(roleAssignment2);

        // ============================================================
        // Create Active Directory groups

        System.out.println("Creating Active Directory group " + groupName1 + "...");
        ActiveDirectoryGroup group1 = authenticated.activeDirectoryGroups()
                .define(groupName1)
                .withEmailAlias(groupEmail1)
                .create();

        System.out.println("Created Active Directory group " + groupName1);
        Utils.print(group1);

        System.out.println("Creating Active Directory group " + groupName2 + "...");
        ActiveDirectoryGroup group2 = authenticated.activeDirectoryGroups()
                .define(groupName2)
                .withEmailAlias(groupEmail2)
                .create();

        System.out.println("Created Active Directory group " + groupName2);
        Utils.print(group2);

        System.out.println("Adding group members to group " + groupName2 + "...");
        group2.update()
                .withMember(user)
                .withMember(servicePrincipal)
                .withMember(group1)
                .apply();
        System.out.println("Group members added to group " + groupName2);
        Utils.print(group2);
于 2019-03-05T23:47:30.963 回答