calendar - 使用 MS Graph 自动接受用户的会议邀请
问题描述
我正在尝试使用服务主体接受会议,该服务主体使用 MS Graph 对 Calendar.Read、Calendar.ReadWrite 具有管理员同意,以便受邀用户不必接受会议。但我不断收到未找到对象的错误。
高级代码:
using Microsoft.Graph;
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using (var httpClient = new HttpClient())
{
string resultjson = "";
string eventId = "Aaakndf8ianffnddd=";
string attendeeUPN = "john@test.com"; //user who has the meeting event
string authToken = GetToken(); //accessToken is generated using servicePrincipal which has Admin Consent on Calendar.Read, Calendars.ReadWrite permissions both on Delegated and Application Type
EventAcceptRequestBody eventAcceptRequestBody = new EventAcceptRequestBody();
eventAcceptRequestBody.SendResponse = false;
string jsonBody = JsonConvert.SerializeObject(eventAcceptRequestBody);
string url = $"https://graph.microsoft.com/v1.0/users/{attendeeUPN}/calendar/events/{eventId}/accept"
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
HttpResponseMessage response = httpClient.PostAsync(url, content).Result;
resultjson = await response.Content.ReadAsStringAsync();
return resultjson;
}
错误: {"error":{"code":"ErrorItemNotFound","message":"在商店中找不到指定的对象。"}}
有谁知道为什么我不断超越错误?谢谢
桑吉夫
解决方案
您可以尝试发出相同的请求,还是尝试通过Graph Explorer获取事件?这将有助于确认事件存在并且 ID 正确。AFAIK,如果您收到 404,则 API 调用工作正常,但不存在具有该 ID 的事件。
推荐阅读
- windows - 如何在 VS Code 中使用 Windows 的内置 OpenSSH ssh-agent,而不是 Git bash?
- spring-mvc - 卷曲测试方法
- java - Java:在计算中使用构造函数,输出总是 0?
- xquery - Xquery 库,用于直接写入文件系统/基础 X 不同的替代方案
- java - 调用 Stage.show() 引发的无法捕获的异常
- javascript - ES6 - 在类中声明原型属性
- python - Python从具有多个值的文件中读取
- python - 如何添加几个模式来检查其中一个是否存在于 python 字符串中?
- android - 以编程方式触发 Google Assistant 以使其朗读给定的字符串
- python - FastAPI 抛出错误(加载 ASGI 应用程序时出错。无法导入模块“api”)