public void CreateEvent(GooglePlusAccessToken serStatus)
        {
            UserCredential credential =
                GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
            {
                ClientId     = "295167635687-bhugb57e9u7tg46ieolrbs636silvljj.apps.googleusercontent.com",
                ClientSecret = "CwUAg3ydCCE1dnA6OshbOJfX",
            },
                    new[] { CalendarService.Scope.Calendar }, "user",
                    CancellationToken.None).Result;

            credential.Token                  = new Google.Apis.Auth.OAuth2.Responses.TokenResponse();
            credential.Token.AccessToken      = serStatus.access_token;
            credential.Token.ExpiresInSeconds = serStatus.expires_in;
            credential.Token.RefreshToken     = serStatus.refresh_token;
            credential.Token.TokenType        = serStatus.token_type;

            var service = new CalendarService(new BaseClientService.Initializer()

            {
                HttpClientInitializer = credential,

                ApplicationName = "ProjectMeet",
            });



            DateTime start = DateTime.Now;



            Google.Apis.Calendar.v3.Data.Event calenderEvent = new Google.Apis.Calendar.v3.Data.Event();



            calenderEvent.Summary = "prueba";

            //calenderEvent.Description = summary;

            //calenderEvent.Location = summary;

            calenderEvent.Start = new Google.Apis.Calendar.v3.Data.EventDateTime

            {
                //DateTime = new DateTime(2018, 1, 20, 19, 00, 0)

                DateTime = start,

                TimeZone = "America/Mexico_City"
            };

            calenderEvent.End = new Google.Apis.Calendar.v3.Data.EventDateTime

            {
                //DateTime = new DateTime(2018, 4, 30, 23, 59, 0)

                DateTime = start.AddHours(1),

                TimeZone = "America/Mexico_City"
            };

            //calenderEvent.Creator = new Google.Apis.Calendar.v3.Data.Event.CreatorData();

            //calenderEvent.Creator.DisplayName = "Jesús Torres";

            //calenderEvent.Creator.Email = "*****@*****.**";



            calenderEvent.Status = "confirmed";

            calenderEvent.Visibility = "public";

            calenderEvent.Description = "EjemploDescripcion";

            var Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" };

            calenderEvent.Recurrence = Recurrence;



            calenderEvent.ConferenceData = new Google.Apis.Calendar.v3.Data.ConferenceData();


            calenderEvent.ConferenceData.CreateRequest = new Google.Apis.Calendar.v3.Data.CreateConferenceRequest();

            calenderEvent.ConferenceData.CreateRequest.ConferenceSolutionKey = new Google.Apis.Calendar.v3.Data.ConferenceSolutionKey();



            calenderEvent.ConferenceData.CreateRequest.ConferenceSolutionKey.Type = "hangoutsMeet";

            calenderEvent.ConferenceData.CreateRequest.Status = new Google.Apis.Calendar.v3.Data.ConferenceRequestStatus();

            calenderEvent.ConferenceData.CreateRequest.Status.StatusCode = "success";

            calenderEvent.ConferenceData.CreateRequest.RequestId = "123456789100";

            var pm = new Dictionary <string, string>
            {
                { "conferenceDataVersion", "1" }
            };


            List <ConferenceParametersAddOnParameters> listParameters = new List <ConferenceParametersAddOnParameters>();
            //listParameters.Add(new ConferenceParametersAddOnParameters { Parameters = {   }, ETag = "1" });
            ConferenceParameters objParam = new ConferenceParameters();

            objParam.AddOnParameters            = new ConferenceParametersAddOnParameters();
            objParam.AddOnParameters.Parameters = pm;
            objParam.ETag = "1";



            calenderEvent.ConferenceData.Parameters = new ConferenceParameters();
            calenderEvent.ConferenceData.Parameters.AddOnParameters            = new ConferenceParametersAddOnParameters();
            calenderEvent.ConferenceData.Parameters.AddOnParameters.Parameters = pm;
            calenderEvent.ConferenceData.Parameters.AddOnParameters.ETag       = "1";

            calenderEvent.ConferenceData.ConferenceSolution = new Google.Apis.Calendar.v3.Data.ConferenceSolution();

            calenderEvent.ConferenceData.ConferenceSolution.Key = new Google.Apis.Calendar.v3.Data.ConferenceSolutionKey();

            calenderEvent.ConferenceData.ConferenceSolution.Key.Type = "hangoutsMeet";



            List <EntryPoint> list = new System.Collections.Generic.List <Google.Apis.Calendar.v3.Data.EntryPoint>();

            EntryPoint entry = new Google.Apis.Calendar.v3.Data.EntryPoint();

            entry.EntryPointType = "video";
            entry.AccessCode     = "123456";

            //list.Add(new Google.Apis.Calendar.v3.Data.EntryPoint { EntryPointType = "video" });

            list.Add(entry);

            //EntryPoint entry = new Google.Apis.Calendar.v3.Data.EntryPoint();

            //entry.EntryPointType = "video";

            calenderEvent.ConferenceData.EntryPoints = list;



            try

            {
                String calendarId = "primary";

                EventsResource.InsertRequest request = service.Events.Insert(calenderEvent, calendarId);

                Event createdEvent = request.Execute();

                Console.WriteLine("Event created: {0}", createdEvent.HtmlLink);
            }

            catch (Exception ex)

            {
            }
        }
Example #2
0
        static void Main(string[] args)

        {
            //UserCredential credential;



            //using (var stream = new FileStream(@"C:\Users\Alien3\Documents\JESUS\VISUAL STUDIO\ZommAPI\Meet\credentials2bien.json", FileMode.Open, FileAccess.Read))

            //{

            //    // The file token.json stores the user's access and refresh tokens, and is created

            //    // automatically when the authorization flow completes for the first time.

            //    string credPath = @"C:\Users\Alien3\Documents\JESUS\VISUAL STUDIO\ZommAPI\Meet\token.json";

            //    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

            //        GoogleClientSecrets.Load(stream).Secrets,

            //        Scopes,

            //        "user",

            //    CancellationToken.None,

            //    new FileDataStore(credPath, true)).Result;

            //    Console.WriteLine("Credential file saved to: " + credPath);

            //}



            string[] scopes = new string[] { CalendarService.Scope.Calendar };

            GoogleCredential credential;

            using (var stream = new FileStream(@"C:\Users\52922\source\repos\DashboardMaterias\Meet\credentials2.json", FileMode.Open, FileAccess.Read))

            {
                credential = GoogleCredential.FromStream(stream)

                             .CreateScoped(scopes);
            }



            credential = credential.CreateScoped(new[] { "https://www.googleapis.com/auth/calendar" });


            try
            {
                Task <string> task = ((ITokenAccess)credential).GetAccessTokenForRequestAsync();
                task.Wait();
                string bearer = task.Result;
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }



            // Create Google Calendar API service.

            var service = new CalendarService(new BaseClientService.Initializer()

            {
                HttpClientInitializer = credential,

                ApplicationName = ApplicationName,
            });



            DateTime start = DateTime.Now;



            Google.Apis.Calendar.v3.Data.Event calenderEvent = new Google.Apis.Calendar.v3.Data.Event();



            calenderEvent.Summary = "prueba";

            //calenderEvent.Description = summary;

            //calenderEvent.Location = summary;

            calenderEvent.Start = new Google.Apis.Calendar.v3.Data.EventDateTime

            {
                //DateTime = new DateTime(2018, 1, 20, 19, 00, 0)

                DateTime = start,

                TimeZone = "America/Mexico_City"
            };

            calenderEvent.End = new Google.Apis.Calendar.v3.Data.EventDateTime

            {
                //DateTime = new DateTime(2018, 4, 30, 23, 59, 0)

                DateTime = start.AddHours(1),

                TimeZone = "America/Mexico_City"
            };

            //calenderEvent.Creator = new Google.Apis.Calendar.v3.Data.Event.CreatorData();

            //calenderEvent.Creator.DisplayName = "Jesús Torres";

            //calenderEvent.Creator.Email = "*****@*****.**";



            calenderEvent.Status = "confirmed";

            calenderEvent.Visibility = "public";

            calenderEvent.Description = "EjemploDescripcion";

            var Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" };

            calenderEvent.Recurrence = Recurrence;



            calenderEvent.ConferenceData = new Google.Apis.Calendar.v3.Data.ConferenceData();


            calenderEvent.ConferenceData.CreateRequest = new Google.Apis.Calendar.v3.Data.CreateConferenceRequest();

            calenderEvent.ConferenceData.CreateRequest.ConferenceSolutionKey = new Google.Apis.Calendar.v3.Data.ConferenceSolutionKey();



            calenderEvent.ConferenceData.CreateRequest.ConferenceSolutionKey.Type = "hangoutsMeet";

            calenderEvent.ConferenceData.CreateRequest.Status = new Google.Apis.Calendar.v3.Data.ConferenceRequestStatus();

            calenderEvent.ConferenceData.CreateRequest.Status.StatusCode = "success";

            calenderEvent.ConferenceData.CreateRequest.RequestId = "123456789100";

            var pm = new Dictionary <string, string>
            {
                { "conferenceDataVersion", "1" }
            };


            List <ConferenceParametersAddOnParameters> listParameters = new List <ConferenceParametersAddOnParameters>();
            //listParameters.Add(new ConferenceParametersAddOnParameters { Parameters = {   }, ETag = "1" });
            ConferenceParameters objParam = new ConferenceParameters();

            objParam.AddOnParameters            = new ConferenceParametersAddOnParameters();
            objParam.AddOnParameters.Parameters = pm;
            objParam.ETag = "1";



            calenderEvent.ConferenceData.Parameters = new ConferenceParameters();
            calenderEvent.ConferenceData.Parameters.AddOnParameters            = new ConferenceParametersAddOnParameters();
            calenderEvent.ConferenceData.Parameters.AddOnParameters.Parameters = pm;
            calenderEvent.ConferenceData.Parameters.AddOnParameters.ETag       = "1";

            calenderEvent.ConferenceData.ConferenceSolution = new Google.Apis.Calendar.v3.Data.ConferenceSolution();

            calenderEvent.ConferenceData.ConferenceSolution.Key = new Google.Apis.Calendar.v3.Data.ConferenceSolutionKey();

            calenderEvent.ConferenceData.ConferenceSolution.Key.Type = "hangoutsMeet";



            List <EntryPoint> list = new System.Collections.Generic.List <Google.Apis.Calendar.v3.Data.EntryPoint>();

            EntryPoint entry = new Google.Apis.Calendar.v3.Data.EntryPoint();

            entry.EntryPointType = "video";
            entry.AccessCode     = "123456";

            //list.Add(new Google.Apis.Calendar.v3.Data.EntryPoint { EntryPointType = "video" });

            list.Add(entry);

            //EntryPoint entry = new Google.Apis.Calendar.v3.Data.EntryPoint();

            //entry.EntryPointType = "video";

            calenderEvent.ConferenceData.EntryPoints = list;



            //Set Remainder

            //calenderEvent.Reminders = new Google.Apis.Calendar.v3.Data.Event.RemindersData()

            //{

            //    UseDefault = false,

            //    Overrides = new Google.Apis.Calendar.v3.Data.EventReminder[]

            //    {

            //                            new Google.Apis.Calendar.v3.Data.EventReminder() { Method = "email", Minutes = 24 * 60 },

            //                            new Google.Apis.Calendar.v3.Data.EventReminder() { Method = "popup", Minutes = 24 * 60 }

            //    }

            //};



            //#region Attendees

            ////Set Attendees

            //calenderEvent.Attendees = new Google.Apis.Calendar.v3.Data.EventAttendee[] {

            //                        new Google.Apis.Calendar.v3.Data.EventAttendee() { Email = "*****@*****.**" }

            //                        //new Google.Apis.Calendar.v3.Data.EventAttendee() { Email = emailAddress }

            //                    };

            //#endregion



            try

            {
                String calendarId = "primary";

                EventsResource.InsertRequest request = service.Events.Insert(calenderEvent, calendarId);

                Event createdEvent = request.Execute();

                Console.WriteLine("Event created: {0}", createdEvent.HtmlLink);
            }

            catch (Exception ex)

            {
            }
        }