简体   繁体   中英

Cetain google calendar events not importing C#

I have built a Calendar application that has the ability to import Google Calendar events. On certain occasions, the event's are returned perfectly. However, some events do not return at all. I cannot narrow down the reason for what might be causing these issues.

Sometimes it's on certain Google 'calendars' and I thought it may be due to security prevention on these particular calendars but I can not find a way to bypass these issues.

This is my code:

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets
    {
        ClientId = "id",
        ClientSecret = "secret",
    },
    new[] { CalendarService.Scope.Calendar },
    accountEmail,
    CancellationToken.None).Result;

var service = new CalendarService(new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = "appname",
});

EventsResource.ListRequest request = service.Events.List(calendarid);

Events events = request.Execute();

foreach (var eventItem in events.Items)
{
    Console.WriteLine(eventItem.Summary);
}

It won't import all this data from a calendar called 'Supplier confirmed dates'

在此处输入图像描述

But it will import the data from this calendar called 'Trade's diary'

在此处输入图像描述

But with another calendar, it will import some events and not others which is why I am confused.

Any suggestions will be welcomed, please.

By default Events: list shows maximum 250 results per page

  • For the calendar where the request won't import all this data it looks like there might be more than 250 events present and thus, not all of them will be retrieved
  • In this case you can either
    • set maxResults to a higher value - up to 2500
    • or retrieve the next page by setting pageToken to the value of nextPageToken you obtained in the response of your first query

I hadn't realized that there was a limit on the number of results that can be returned from the Google calendar. Since my calendar had more than the limit of '250' it was returning the first '250' then stopping so I upped this limit to '2500' (the maximum it can return) and it worked perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM