簡體   English   中英

使用Java Microsoft graph SDK在Outlook中添加成員

[英]add member in Outlook using Java Microsoft graph SDK

我正在嘗試使用Java中的Microsoft Graph API將用戶添加到Outlook中的組。 我已參考開發人員指南: https : //developer.microsoft.com/zh-cn/graph/docs/api-reference/beta/api/group_post_members用於添加用戶。

但是要實現這一點,我正在使用Microsoft graph java sdk ,我需要在java的組中添加具有成員IDjson對象,例如

POST https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
Content-type: application/json
Content-length: 30
{
    "@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
}

請讓我知道如何在Java的請求主體中添加json對象。

我的代碼如下所示:

公共無效addMemberToGroup(String groupId,String userId){

            Group group =  mGraphServiceClient
                                              .groups(groupId)
                                              .buildRequest()
                                              .get();

                JsonObject payload1 = new JsonObject();
                        IJsonBackedObject requestBody = new ReferenceRequestBody("https://graph.microsoft.com/v1.0/users/78276c08-9802-4108-8b20-d70cff6666e5");

                        mGraphServiceClient
                        .groups(groupId)
                        .members(userId)
                        .buildRequest()
                        .post(user,requestBody);

}

有了這個我得到如下錯誤:

嚴重:可拋出詳細信息:com.microsoft.graph.http.GraphServiceException:錯誤代碼:BadRequest錯誤消息:只在包含的實體上支持寫請求

POST https://graph.microsoft.com/v1.0/groups/5877490c-54fe-45fb-b288-b5d0f6902058/members/78276c08-9802-4108-8b20-d70cff6666e5 SdkVersion:graph-java-v0.2.0授權:Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI [...] {“ @ odata.id”:“ https://graph.microsoft.com/v1.0/use [...]

400:錯誤的請求[...]

請讓我知道我該如何解決。

應該是這樣的:

User user = new User();
user.id=userId;

mGraphServiceClient.groups(groupId).members().references().buildRequest().post(user);

要么

DirectoryObject directoryObject = new DirectoryObject();
directoryObject.id = userId;  

mGraphServiceClient.groups(groupId).members().references().buildRequest().post(directoryObject);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM