MS Graph 创建团队会议错误请求"onlinemeeting cannot be null."



我正试图使用HttpPost请求通过web应用程序创建一个会议,但我收到了一个400 BadRequest错误,消息为"onlinemeeting不能为null">

HttpPost httpPost = new HttpPost("https://graph.microsoft.com/v1.0/me/onlineMeetings");

LocalDateTime meetingTime = java.time.LocalDateTime.now();

try {
JSONObject bodyJson = new JSONObject();

bodyJson.put("meetingType", "meetNow"); //tried with and without this and still didn't work
bodyJson.put("startDateTime", meetingTime.toString());
bodyJson.put("subject", "TeamsMeeting");
bodyJson.put("participants", new JSONObject().put("organizer", 
new JSONObject().put("identity", 
new JSONObject().put("user", 
new JSONObject().put("id", userId)))));

StringEntity entity = new StringEntity(bodyJson.toString());
entity.setContentType("application/json");
httpPost.setEntity(entity);

BasicHeader authHeader = new BasicHeader("Authorization", "Bearer " + teamsToken);
httpPost.addHeader(authHeader);
httpPost.addHeader("Content-Type", "application/json");


HttpResponse postResponse = httpClient.execute(httpPost);
String responseContent = EntityUtils.toString(postResponse.getEntity(), StandardCharsets.UTF_8.name());
...

我在执行帖子请求时得到了这个:

{
"error": {
"code":"BadRequest",
"message":"onlinemeeting cannot be null.",
"innerError": {
"date":"2020-07-10T19:09:48",
"request-id":"cfad7871-6595-4efb-a262-13ac42f0e599"
}
}
}

当我使用邮递员时,它可以工作,但当我通过网络应用程序点击它时,我就不能了。你知道是什么原因造成的吗?Java代码中有什么错误吗?感谢您的帮助。

如果您使用用户令牌创建在线会议,则MS Graph中存在使用Java的OnlineMeeting文档。

IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
OnlineMeeting onlineMeeting = new OnlineMeeting();
onlineMeeting.startDateTime = "2019-07-12T21:30:34.2444915+00:00";
onlineMeeting.endDateTime = "2019-07-12T22:00:34.2464912+00:00";
onlineMeeting.subject = "User Token Meeting";
graphClient.me().onlineMeetings()
.buildRequest()
.post(onlineMeeting);

如果您使用应用程序令牌创建在线会议,请尝试以下代码:

IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
OnlineMeeting onlineMeeting = new OnlineMeeting();
onlineMeeting.startDateTime = "2019-07-12T21:30:34.2444915+00:00";
onlineMeeting.endDateTime = "2019-07-12T22:00:34.2464912+00:00";
onlineMeeting.subject = "Application Token Meeting";
MeetingParticipants meetingParticipants = new MeetingParticipants();
meetingParticipants.organizer.identity.user.id = "550fae72-d251-43ec-868c-373732c2704f";
onlineMeeting.participants = meetingParticipants;

graphClient.me().onlineMeetings()
.buildRequest()
.post(onlineMeeting);

有关类OnlineMeeting的更多详细信息,请参阅此处。

使用以下代码对我有效:

OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, json);
Request request = new Request.Builder()
.url(authHelper.getMsGraphEndpointHost() + url)
.post(body)
.addHeader("content-type", "application/json")
.addHeader("authorization", accessToken)
.addHeader("cache-control", "no-cache")
.build();
Response responseOk = client.newCall(request).execute();

问题最终出现在startDateTime上,因为我认为它的格式不符合要求。错误消息没有表明它是那个值,但一旦从json主体中删除了这个值,它就可以在不使用OnlineMeeting对象的情况下工作了。

相关内容

最新更新