2

In my asp.net core app I'm going to add new event to google calendar. But it showing error in google. I have enabled calendar api and insert ClientId and ClientSecret. But it showing error.

enter image description here

This is my code below. enter image description here and enter image description here

   public void CreateEvent(string email, string text)
    {
        UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        new ClientSecrets
                        {
                            ClientId = "461480317556-xxxxxxxxxxg.apps.googleusercontent.com",
                            ClientSecret = "RljgIL79D2YFkmVaWQypCjIa",
                        },
                        new[] { CalendarService.Scope.Calendar },"user",CancellationToken.None).Result;

        // Create the service.
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Calendar API Sample",
        });

        Event myEvent = new Event
        {
            Summary = "Appointment",
            Location = "Somewhere",
            Start = new EventDateTime()
            {
                DateTime = new DateTime(2014, 6, 2, 10, 0, 0),
                TimeZone = "America/Los_Angeles"
            },
            End = new EventDateTime()
            {
                DateTime = new DateTime(2014, 6, 2, 10, 30, 0),
                TimeZone = "America/Los_Angeles"
            },
            Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO" },Attendees = new List<EventAttendee>(){new EventAttendee() { Email = email } }
        };

        Event recurringEvent = service.Events.Insert(myEvent, "primary").Execute();

    }
Isanka Thalagala
  • 1,625
  • 3
  • 16
  • 32
  • 1
    the error is saying the URL you're using isn't one which is registered for use with that client secret. AFAIK you can't use localhost for this. https://stackoverflow.com/a/19296805/5947043 may be informative. – ADyson Jun 12 '18 at 10:19

1 Answers1

3

I have resolved issue my self.Problem was I have put type as "Web Application" Instead of "other".. After I changed it to type as "other" It worked.

enter image description here

Isanka Thalagala
  • 1,625
  • 3
  • 16
  • 32