[英]MS Graph create teams meeting Bad Request “onlinemeeting cannot be null.”
我正在嘗試使用 HttpPost 請求通過 web 應用程序創建會議,但收到 400 BadRequest 錯誤消息“onlinemeeting cannot be 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"
}
}
}
當我使用 postman 時它可以工作,但通過我的 web 應用程序點擊它時我不能。 有什么想法可能導致這種情況嗎? 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);
有關 Class 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 object。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.