Google Calendar API - Not Returning From Execute() C#

前端 未结 2 926
情深已故
情深已故 2021-01-25 06:35

Running the code below never returns from the Execute function. I have a private calendar on my personal gmail account that I have shared with the developer.gserviceaccount.com

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 07:29

    There is a difference between a calendar and calendarlist. In the Google Calendar website calendarlist appears on the left hand side its a list of calendars. However for a calendar to appear on calendarlist it has to be added to the calendarlist.

    You gave your service account access to the calendar but did you programmatically tell it to add the calendar to its calendarlist? You should have used CalendarList: insert

    I am not sure why you want to get the calendarlist. Personally I think you should just go with Calendars: get you already know the ID of the calendar from the google calendar website.

    Tip: Execute is going to return an object I am not sure .ToString() on it is really the best idea.

    update code:

    /// 
            /// Returns metadata for a calendar. 
            /// Documentation:https://developers.google.com/google-apps/calendar/v3/reference/calendars/get
            /// 
            /// Valid Autenticated Calendar service
            /// Calendar identifier.
            /// Calendar resorce: https://developers.google.com/google-apps/calendar/v3/reference/calendars#resource 
            public static Calendar get(CalendarService service, string id)
            {
                try
                {
                   return service.Calendars.Get(id).Execute();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return null;
                }
            }
    

    code from My sample project on GitHub

提交回复
热议问题