404 在 C# 中访问 Public Google API Calendar v3 时出错
404 Error accessing Public Google API Calendar v3 in C#
尝试访问 public 日历时出现此错误:
An unhandled exception of type 'Google.GoogleApiException' occurred in mscorlib.dll
Google.Apis.Requests.RequestError
Not Found [404]
Errors [
Message[Not Found] Location[ - ] Reason[notFound] Domain[global]
当我使用简单的 GET HTTP 调用 Google API 时,我的 API 键和 CalendarID 工作。
我在这里使用博客 post 创建了这段代码:https://www.daimto.com/public-google-calendars-with-c/
我的代码:
class Program
{
static void Main(string[] args)
{
var service = new CalendarService(new BaseClientService.Initializer()
{
ApiKey = "My API Key From Google Console",
ApplicationName = "I put my API Key name from Google Console here",
});
var events = service.Events.List("thefirstacademy.org_2ldo8np1v5tr1qlpbho6ip6tog%40group.calendar.google.com").Execute();
foreach (var myEvent in events.Items)
{
Console.WriteLine(string.Format("Event: {0} Start: {1} End: {2}", myEvent.Summary, myEvent.Start.DateTime.ToString(), myEvent.End.DateTime.ToString()));
}
}
}
我找到了答案。使用的日历 ID 必须在 "group.calendar.google.com" 部分之前有一个 @ 符号。尽管 ID 在 GET HTTP 中有效,但在 C# 中的 Google.API.Calendar.V3 中无效。
尝试访问 public 日历时出现此错误:
An unhandled exception of type 'Google.GoogleApiException' occurred in mscorlib.dll
Google.Apis.Requests.RequestError
Not Found [404]
Errors [
Message[Not Found] Location[ - ] Reason[notFound] Domain[global]
当我使用简单的 GET HTTP 调用 Google API 时,我的 API 键和 CalendarID 工作。
我在这里使用博客 post 创建了这段代码:https://www.daimto.com/public-google-calendars-with-c/
我的代码:
class Program
{
static void Main(string[] args)
{
var service = new CalendarService(new BaseClientService.Initializer()
{
ApiKey = "My API Key From Google Console",
ApplicationName = "I put my API Key name from Google Console here",
});
var events = service.Events.List("thefirstacademy.org_2ldo8np1v5tr1qlpbho6ip6tog%40group.calendar.google.com").Execute();
foreach (var myEvent in events.Items)
{
Console.WriteLine(string.Format("Event: {0} Start: {1} End: {2}", myEvent.Summary, myEvent.Start.DateTime.ToString(), myEvent.End.DateTime.ToString()));
}
}
}
我找到了答案。使用的日历 ID 必须在 "group.calendar.google.com" 部分之前有一个 @ 符号。尽管 ID 在 GET HTTP 中有效,但在 C# 中的 Google.API.Calendar.V3 中无效。