简体   繁体   中英

Filtering Google Calendar events with .C# API

I try to filter Google Calendar events by date in a .Net program.

I found resources only in other environnements.

The following code retrieves all events. The optional parameters are not used :-(

I think I do not send them to Google at all. I do not understand the "ParameterType" use and found no list of valid values. I simply copied the original parameter "ParameterType" value.

Any help will be apreciated!

var rq = service.Events.List( "primary" );
string startRFC3339 = "2017-04-19T00:00:00Z";
string endRFC3339 = "2017-04-22T00:00:00Z";
rq.RequestParameters["timeMin"] = new Google.Apis.Discovery.Parameter() {
  Name = "timeMin",
  ParameterType = "query",
  DefaultValue = startRFC3339
};
rq.RequestParameters["timeMax"] = new Google.Apis.Discovery.Parameter() {
  Name = "timeMax",
  ParameterType = "query",
  DefaultValue = endRFC3339
};
var events = requete.Execute();

I found the answer: do not focus on the RequestParameters collection. It describes allowed parameters. It doesn't contain the parameters values. Those values are in the request object itself:

var rq = service.Events.List( "primary" );
rq.TimeMin = aDateTime;
rq.TimeMax = aDateTime.AddDays(1);
var events = rq.Execute();

So simple...

.Net is strongly typed. I should have looked there first.

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