我正在尝试使用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代码有什么问题吗?任何帮助表示赞赏。
答案 0 :(得分:0)
如果您使用用户令牌创建在线会议,则MS Graph中的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);
的Java。
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
有关类using UnityEngine;
public class BikeController : MonoBehaviour
{
public float speed = 1500;
public float rotationSpeed = 10f;
public WheelJoint2D backWheel;
public WheelJoint2D frontWheel;
public Rigidbody2D rb;
private float movement = 0f;
private float rotation = 0f;
public Transform player;
void Update()
{
movement = Input.GetAxisRaw("Horizontal") * speed;
rotation = Input.GetAxisRaw("Vertical");
if (Input.touchCount > 0)
{
Touch tch = Input.GetTouch(0);
if (tch.position.x > player.position.x)
{
movement = speed;
}
if (tch.position.x < player.position.x)
{
movement = -speed;
}
}
}
void FixedUpdate()
{
if (movement == 0f)
{
backWheel.useMotor = false;
frontWheel.useMotor = false;
}
else
{
backWheel.useMotor = true;
frontWheel.useMotor = true;
JointMotor2D motor = new JointMotor2D { motorSpeed = movement, maxMotorTorque = 10000 };
backWheel.motor = motor;
frontWheel.motor = motor;
}
rb.AddTorque(rotation * rotationSpeed * Time.fixedDeltaTime);
}
}
的更多详细信息,请参见doc。
答案 1 :(得分:0)
使用以下代码对我有用:
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();
答案 2 :(得分:0)
问题最终出在了startDateTime上,因为我认为它的格式不正确。该错误消息并未表明它是该值,但是一旦将其从json主体中删除,它就可以工作,而不必使用OnlineMeeting对象。