コード例 #1
0
        public static IList ListEvents(GoogleAccountRequest info)
        {
            Authenticate(info);
            CalendarService service = InitService();

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("primary");
            //request.TimeMin = DateTime.Now;
            request.ShowDeleted  = false;
            request.SingleEvents = true;
            request.MaxResults   = 10;
            request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            var lst = new List <Event>();

            do
            {
                Events events = request.Execute();

                if (events.Items != null && events.Items.Count > 0)
                {
                    lst.AddRange(events.Items.ToList());
                }
                request.PageToken = events.NextPageToken;
            }while (!string.IsNullOrEmpty(request.PageToken));

            return(lst);
        }
コード例 #2
0
        public static void InsertGoogleAPIEvent(GoogleAccountRequest googleRequest)
        {
            try
            {
                Authenticate(googleRequest);
                CalendarService service = InitService();

                MyCalendarEvent myEvent  = googleRequest.CalendarEvent;
                Event           newEvent = new Event()
                {
                    Summary     = myEvent.SummaryText,
                    Location    = myEvent.LocationText,
                    Description = myEvent.Description,
                    Start       = new EventDateTime()
                    {
                        DateTime = myEvent.BeginDate,
                        TimeZone = IsraelDefaultTimeZone,
                    },
                    End = new EventDateTime()
                    {
                        DateTime = myEvent.EndDate,
                        TimeZone = IsraelDefaultTimeZone,
                    },


                    Reminders = new Event.RemindersData()
                    {
                        UseDefault = false,
                        Overrides  = new EventReminder[]
                        {
                            new EventReminder()
                            {
                                Method = "popup", Minutes = 24 * 60
                            },
                            new EventReminder()
                            {
                                Method = "popup", Minutes = 15
                            },
                            new EventReminder()
                            {
                                Method = "popup", Minutes = 3 * 60
                            },
                        }
                    }
                };
                if (!string.IsNullOrEmpty(myEvent.Frequency) && myEvent.FrequencyCount > 0)
                {
                    newEvent.Recurrence = new String[] { $"RRULE:FREQ={myEvent.Frequency};COUNT={myEvent.FrequencyCount}" }
                }
                ;

                String calendarId = "primary";
                EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
                Event createdEvent = request.Execute();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
 private static void Authenticate(GoogleAccountRequest info)
 {
     using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(info.CredentialsJsonString)))
     {
         credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
             GoogleClientSecrets.Load(stream).Secrets,
             Scopes,
             "user",
             CancellationToken.None, new GoogleDatabaseDataStore(info.GoogleDataStore)).Result;
     }
 }