【发布时间】:2018-11-04 11:58:11
【问题描述】:
我正在尝试使用 Java 中的 Microsoft Graph API 将用户添加到 Outlook 中的组。我参考了开发者指南:https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/group_post_members 用于添加用户。
但是要实现这一点,我使用的是 Microsoft graph java sdk,我需要在组中添加具有成员 Id 的 json 对象在java中,像
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 对象。
我的代码如下:
public void 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 错误消息:仅包含的实体支持写入请求
发布https://graph.microsoft.com/v1.0/groups/5877490c-54fe-45fb-b288-b5d0f6902058/members/78276c08-9802-4108-8b20-d70cff6666e5 SdkVersion : 图-java-v0.2.0 授权:承载 eyJ0eXAiOiJKV1QiLCJub25jZSI[...] {"@odata.id":"https://graph.microsoft.com/v1.0/use[...]
400 : 错误请求 [...]
请告诉我如何解决这个问题。
【问题讨论】:
-
这看起来应该可以。您是否尝试通过Graph Explorer 发出请求以查看服务是否允许?