首页 > 解决方案 > 使用 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":"在商店中找不到指定的对象。"}}

有谁知道为什么我不断超越错误?谢谢

桑吉夫

标签: calendarmicrosoft-graph-apimicrosoft-graph-calendar

解决方案


您可以尝试发出相同的请求,还是尝试通过Graph Explorer获取事件?这将有助于确认事件存在并且 ID 正确。AFAIK,如果您收到 404,则 API 调用工作正常,但不存在具有该 ID 的事件。


推荐阅读