-2

Well.. I'm trying this code to create an Event

            CalendarService service;
            GoogleCredential credential;

            try
            {
                string[] scopes = new string[] { CalendarService.Scope.Calendar };
                using (var stream = new FileStream(@"C:\Prueba\meet.json", FileMode.Open, FileAccess.Read))
                {
                    credential = GoogleCredential.FromStream(stream)
                    .CreateScoped(scopes);
                }
                service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential
                });


                Event calendarEvent = new Event();
                DateTime start = DateTime.Now;
                calendarEvent.Kind = "";
                calendarEvent.Summary = "prueba";
                calendarEvent.Status = "confirmed";
                calendarEvent.Visibility = "public";
                calendarEvent.Description = "prueba";

                calendarEvent.Creator = new Event.CreatorData
                {
                    Email = "email@example.com", //email@example.com
                    Self = true
                };

                calendarEvent.Organizer = new Event.OrganizerData
                {
                    Email = "email@example.com",
                    Self = true
                };

                calendarEvent.Start = new EventDateTime
                {
                    DateTime = start,
                    TimeZone = "America/Mexico_City"
                };

                calendarEvent.End = new EventDateTime
                {
                    DateTime = start.AddHours(1),
                    TimeZone = "America/Mexico_City"
                };

                calendarEvent.Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=1" };
                calendarEvent.Sequence = 0;
                calendarEvent.HangoutLink = "";

                calendarEvent.ConferenceData = new ConferenceData
                {
                    CreateRequest = new CreateConferenceRequest
                    {
                        RequestId = "1234abcdef",
                        ConferenceSolutionKey = new ConferenceSolutionKey
                        {
                            Type = "hangoutsMeet"
                        },
                        Status = new ConferenceRequestStatus
                        {
                            StatusCode = "success"
                        }
                    },
                    EntryPoints = new List<EntryPoint>
                    {
                        new EntryPoint
                        {
                            EntryPointType = "video",
                            Uri = "",
                            Label = ""
                        }
                    },
                    ConferenceSolution = new ConferenceSolution
                    {
                        Key = new ConferenceSolutionKey
                        {
                            Type = "hangoutsMeet"
                        },
                        Name = "Google Meet",
                        IconUri = ""
                    },
                    ConferenceId = ""
                };

                //calendarEvent.EventType = "default";


                EventsResource.InsertRequest request = service.Events.Insert(calendarEvent, "email@example.com");
                request.ConferenceDataVersion = 0;
                Event createEvent = request.Execute();
                string url = createEvent.HangoutLink;
            }
            catch (Exception ex)
            {

            }

The source code is here

When I execute the line 116: Event createEvent = request.Execute(); I get this error: Google.Apis.Requests.RequestError Invalid conference type value. [400] Errors [Message[Invalid conference type value.] Location[ - ] Reason[invalid] Domain[global]

I don't know what means this error o with line I wrong Could anyone help me with an example to create an event using classes C# from Google API Calendar?

1 Answers1

1

As described in the C# library documentation for createRequest:

Either conferenceSolution and at least one entryPoint, or createRequest is required.

This means that you should use only CreateConferenceRequest as this conference is brand new (if it already existed then you would be wanting to use ConferenceSolution along with EntryPoints ). Therefore, simply remove ConferenceSolution and EntryPoints to leave just CreateConferenceRequest which as specified in the documentation is used for generating a new conference and attach it to the event.

Mateo Randwolf
  • 2,823
  • 1
  • 6
  • 17
  • I just tried but I keep getting the same error, is it not because I use a gmail account through a service account? – Jesús Torres Torres Feb 08 '21 at 12:02
  • Have you [set up your service account](https://developers.google.com/identity/protocols/oauth2/service-account) and authorization propperly? Can you make other more simple requests (like [Calendar.get()](https://developers.google.com/calendar/v3/reference/calendars/get)) with that service account successfully ? Have you granted [domain wide delegation](https://developers.google.com/admin-sdk/directory/v1/guides/delegation) to your service account? – Mateo Randwolf Feb 09 '21 at 10:45
  • yes, in fact I can create events using the service account, the only thing it doesn't generate is the HangoutLink – Jesús Torres Torres Feb 10 '21 at 15:58
  • 1
    So you can create the event you showed in the question successfully if you remove the ```ConferenceData``` part right? Could you try the suggestion of my answer and also changing ```request.ConferenceDataVersion = 0;``` to ```request.ConferenceDataVersion = 1;```? According to [the documentation](https://developers.google.com/resources/api-libraries/documentation/calendar/v3/csharp/latest/classGoogle_1_1Apis_1_1Calendar_1_1v3_1_1EventsResource_1_1ImportRequest.html#a63907ce6341a977299e027bf219e3fe6), having it set to ```0``` means that it assumes to not have any conference data support. – Mateo Randwolf Feb 15 '21 at 15:46