当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How do I get more than 250 calendar items using the .net client library?

问题描述:

I'm trying to use the .net client library for Google Calendar. I can get a list of Calendars and get a list of events on a Calendar. However, I get a maximum of 250 items per Calendar. How do I access the rest? I'm aware of the 'pagetoken' in Google.Apis.Calendar.v3.EventsResource.ListRequest, however in the code example below, itemlistreq.PageToken remains null, even for a calendar with more than 250 items.

var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);

var initializer = new BaseClientService.Initializer();

initializer.Authenticator = auth;

var calsrv = new CalendarService(initializer);

//Get list of calendars

var list = calsrv.CalendarList.List().Execute().Items;

//Get entry list for each calendar

foreach(var cal in list)

{

var itemlistreq = calsrv.Events.List(cal.Id);

var itemlistex = itemlistreq.Execute();

var itemlist = itemlistex.Items;

//Here, itemlistreq.PageToken == null, even if itemlist has 250 entries.

}

网友答案:

Did you try to change the MaxResult property on the request? For example, try doing the following:

var itemlistreq = calsrv.Events.List(cal.Id);
itemlistreq.MaxResults = 10000;
var itemlistex = itemlistreq.Execute();
var itemlist = itemlistex.Items;

UPDATED: Try getting the NextPageToekn property from the Events class (itemlistex in your case)

var itemlistreq = calsrv.Events.List(cal.Id);
var itemlistex = itemlistreq.Execute();
var token = itemlistex.NextPageToken; // THAT IS THE TOKEN YOU ARE LOOKING FOR
var itemlist = itemlistex.Items;

Then you can set it on the itemlistex.PageToken property to get more events...

网友答案:

the MaxResult is limited to 2500 items, so 10000 will not work

分享给朋友:
您可能感兴趣的文章:
随机阅读: