问题描述
我一直在尝试使用图api从组中创建一个团队,但是我一直遇到错误。 我尝试了几种变体。
变化1
Map<String,JsonElement> additionalData = new HashMap<String,JsonElement>();
additionalData.put("group@odata.bind",new JsonPrimitive("https://graph.microsoft.com/v1.0/groups('902e46a0-471f-4e41-9c33-77abae63245d')"));
additionalData.put("template@odata.bind",new JsonPrimitive("https://graph.microsoft.com/beta/teamstemplates('standard')"));
team.additionalDataManager().putAll(additionalData);
HeaderOption option = new HeaderOption("Authorization","Bearer " + result.accesstoken());
ITeamCollectionRequest res = graphClient.teams().buildrequest(Arrays.asList(option));
res.post(team);
变化2
Map<String,JsonElement>();
additionalData.put("template@odata.bind",new JsonPrimitive("https://graph.microsoft.com/beta/teamstemplates('standard')"));
HeaderOption option = new HeaderOption("Authorization","Bearer " + result.accesstoken());
ITeamRequest req = graphClient.groups("902e46a0-471f-4e41-9c33-77abae63245d").team().buildrequest(Arrays.asList(option));
req.post(team);
在这两种版本中,我最终都会遇到诸如502 Bad Gateway无法执行后端请求或404 NOT FOUND未知错误之类的错误。
我正在使用图sdk-1.7.1与Java。 任何帮助将不胜感激。
解决方法
我认为您正在混合两件事:
- 将组升级为团队->这不接受模板,而是通过PUT请求完成的。
- 使用模板创建团队->这不接受组,而是通过POST请求完成的。
第一个选项应如下所示:
HeaderOption option = new HeaderOption("Authorization","Bearer " + result.accessToken());
ITeamRequest req = graphClient.groups("902e46a0-471f-4e41-9c33-77abae63245d").team().buildRequest(Arrays.asList(option));
req.put();
第二个选项应如下所示:
Map<String,JsonElement> additionalData = new HashMap<String,JsonElement>();
additionalData.put("template@odata.bind",new JsonPrimitive("https://graph.microsoft.com/beta/teamsTemplates('standard')"));
team.additionalDataManager().putAll(additionalData);
HeaderOption option = new HeaderOption("Authorization","Bearer " + result.accessToken());
ITeamRequest req = graphClient.teams().buildRequest(Arrays.asList(option));
req.post(team);