Google日历在ASP .net中添加事件:验证失败

时间:2018-06-12 08:19:46

标签: asp.net-mvc google-api google-calendar-api

在我的asp.net核心应用程序中,我将向谷歌日历添加新事件。但它在谷歌显示错误。我已启用日历api并插入ClientId和ClientSecret。但它显示错误。

enter image description here

这是我的代码如下。 enter image description hereenter 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();

    }

1 个答案:

答案 0 :(得分:3)

我已经解决了自己的问题。问题是我把类型作为&#34; Web应用程序&#34;而不是&#34;其他&#34; ..之后我将其改为键入为&#34;其他&#34;它奏效了。

enter image description here