Google Calendar .NET API Sort by Date

I read documents and played with various EventQuery parameters for several days. I am using C # .NET with google.net api to get events from the public calendar that I configured. I can get events from the api just fine, but I can not get it to give me the next upcoming events by date. Ambiguous events with one-time events occur on my calendar. I read material on the Internet to use direct query parameter strings in uri request, but it doesn't seem to work correctly when using it in a .net api structure. Here is what I currently have as my base:

CalendarService myService = new CalendarService("testGoogleCalendar-1");
EventQuery myQuery = new EventQuery();
myQuery.Uri = new Uri(CalendarURI);
myQuery.NumberToRetrieve = NumberOfEvents;
EventFeed calFeed = myService.Query(myQuery);
foreach (AtomEntry entry in calFeed.Entries)
{
    LiteralControl test = new LiteralControl("<p><b>" + entry.Title.Text + "</b></p>");
    this.Controls.Add(test);
}            

I tried to play with EventQuery members StartDate, StartTime, EndTime, SortOrder, FutureEvents and even tried to add "? Orderby = starttime" to the local CalendarURI element.

It seems that the api request returns the order of the published date of the event when I created the event on the calendar when the event does not happen.

I am also trying to get only the date and time of the event from the AtomEntry object so that I can sort it myself and format it with a title in my control, but the only place I see in AtomEntry is Content.Content which also has other things that I really I do not want. Is there a DateTime member for AtomEntry for this, so I can just get the date?

It really pissed me off right now, so any help is appreciated.

+3
7

API GData .NET, Java. . , "" . <gd:when> - , .

, orderby=starttime . , WireShark - , , - API, - , , Uri - ...

:

query.ExtraParameters = "orderby=starttime";

? , uri...

+4
 myQuery.ExtraParameters = "orderby=starttime&sortorder=ascending";

!

+4

, OP, , . , -;)

var query = new EventQuery(FEED_URL);    
query.SortOrder = CalendarSortOrder.ascending;
+1

Google Doc API :

EventQuery myQuery = new EventQuery(feedUrl);
myQuery.StartTime = new DateTime(2007, 1, 5);
myQuery.EndTime = new DateTime(2007, 1, 7);

EventFeed myResultsFeed = myService.Query(myQuery);

.

0

, - Linq.

public static IEnumerable<EventDto> FindTopEvent(this AtomEntryCollection items, int cnt)
{
    return (from  item in items.OfType<EventEntry>()
            select new EventDto
            {
                Url = item.FeedUri,
                Title = item.Title.Text,
                Date = item.Times[0].StartTime.ToShortDateString()
            }).Take(cnt);
}

, - :

Date = (item.Times.Count > 0) ? item.Times[0].StartTime.ToShortDateString() : ""

, SingleEvent EventQuery true .

0
EventQuery query = new EventQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/" + this.Service.Credentials.Username + "/private/full");
query.ExtraParameters = "orderby=starttime&sortorder=ascending";
query.SingleEvents = true;
query.StartTime = DateTime.Now;
query.EndTime = DateTime.Now.AddDays(7.0);

EventFeed calFeed = this.Service.Query(query);

List<SyndicationItem> items = new List<SyndicationItem>();
foreach (var entry in calFeed.Entries)
{
   EventEntry eventEntry = entry as Google.GData.Calendar.EventEntry;
   if (eventEntry != null)
   {
      if (eventEntry.Times.Count != 0)
      {
         DateTime dt = eventEntry.Times[0].StartTime;
    }
}

.

0
source

You can also make sure that you are not getting a canceled event that you might encounter if you only delete the first occurrence of a recurring event, and then you delete the remaining events in the sequence. These remaining events in the sequence that you deleted were not actually deleted, and their status was canceled overs.

The only way to not read these events in your code is to check the EventEntry Status property.

0
source

Source: https://habr.com/ru/post/1711355/


All Articles