我正在尝试使用Java中的micorosoft图形API将用户添加到Outlook中的组。我已提到https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/group_post_members 用于添加用户。
但是要实现这一点,我正在使用 microsoft graph java sdk ,并且我需要在组中添加成员 Id 的 json 对象在Java中。
请让我知道如何在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}"
}
答案 0 :(得分: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);