Google calendar api 删除事件时未找到Google.api.Requests.RequestError

Google calendar api 删除事件时未找到Google.api.Requests.RequestError,google-calendar-api,Google Calendar Api,我有以下方法删除日历中的事件: 公共异步任务DeleteEventInCalendarAsync(令牌响应令牌、字符串googleUserId、字符串calendarId、字符串eventId) { 字符串结果=null; 尝试 { 如果(_calService==null) { _calService=GetCalService(令牌,googleUserId); } //检查事件是否存在 var eventResource=new EventsResource(_calService); v

我有以下方法删除日历中的事件:

公共异步任务DeleteEventInCalendarAsync(令牌响应令牌、字符串googleUserId、字符串calendarId、字符串eventId)
{
字符串结果=null;
尝试
{
如果(_calService==null)
{
_calService=GetCalService(令牌,googleUserId);
}
//检查事件是否存在
var eventResource=new EventsResource(_calService);
var erListRequest=eventResource.List(calendarId);
var events response=await erListRequest.ExecuteAsync().ConfigureAwait(false);
var existingEvent=eventsResponse.Items.FirstOrDefault(e=>e.Id==eventId);
如果(existingEvent!=null)
{
var deleteRequest=new EventsResource.deleteRequest(\u calService,calendarId,eventId);
结果=等待deleteRequest.ExecuteAsync().ConfigureAwait(false);
}
}
捕获(异常exc)
{
结果=空;
_logService.LogException(exc);
}
返回结果;
}
我得到的错误如下-

Google.GoogleApiException Google.Apis.Requests.RequestError Not Found [404] Errors [ Message[Not Found] Location[ - ] Reason[notFound] Domain[global] ]

你能帮我理解这个错误的原因吗?或者在哪里可以找到有关这些错误的详细信息?

您收到的错误是由于您正在传递的事件id不存在或以错误的方式传递。接下来,我制作了一个简单的代码示例,说明如何从类事件中将事件id传递给删除(string calendarId,string eventId)方法

命名空间日历快速启动
{
班级计划
{
//如果修改这些作用域,请删除以前保存的凭据
//位于~/.credentials/calendar-dotnet-quickstart.json
静态字符串[]范围={CalendarService.Scope.Calendar};
静态字符串ApplicationName=“谷歌日历API.NET快速启动”;
静态void Main(字符串[]参数)
{
用户凭证;
使用(var)流=
新文件流(“credentials.json”、FileMode.Open、FileAccess.Read))
{
//文件token.json存储用户的访问和刷新令牌,并被创建
//首次完成授权流时自动执行。
字符串credPath=“token.json”;
凭证=GoogleWebAuthorizationBroker.AuthorizationAsync(
GoogleClientSecrets.Load(stream.Secrets),
范围,
“用户”,
取消令牌。无,
新文件数据存储(credPath,true))。结果;
Console.WriteLine(“凭证文件保存到:”+credPath);
}
//创建谷歌日历API服务。
var service=new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=ApplicationName,
});
//定义请求。
EventsResource.ListRequest请求=service.Events.List(“主”);
//列出事件。
Events=request.Execute();
Event existingEvent=events.Items.FirstOrDefault(e=>e.Id==“您想要获取的事件Id”);
Console.WriteLine(“即将到来的事件:”);
如果(existingEvent!=null)
{
WriteLine(“{0}{1}”,existingEvent.Summary,existingEvent.Id);
字符串deleteEvent=service.Events.Delete(“primary”,existingEvent.Id).Execute();
}
其他的
{
Console.WriteLine(“未找到即将发生的事件”);
}
Console.Read();
}
}
}
通知 为了在控制台中进行测试,我以同步语法的方式制作了这个示例。在您测试它并了解它是如何工作的之后,您可以根据您的代码调整它。请记住,如果您传递的是正确的Id

文件 有关更多信息,请查看此文档: