简体   繁体   中英

404 Error accessing Public Google API Calendar v3 in C#

When trying to access a public calendar I get this error:

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]

My API Key and CalendarID work when I call Google API with a simple GET HTTP.

I used the blog post here to create this code: https://www.daimto.com/public-google-calendars-with-c/

MyCode:

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()));
        }
    }
}

I found the answer. The Calendar ID used has to have an @ sign before the "group.calendar.google.com" part. Even though the ID worked in the GET HTTP, it didn't work in the Google.API.Calendar.V3 in C#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM