googleapis / google-api-dotnet-client

Google APIs Client Library for .NET
https://developers.google.com/api-client-library/dotnet
Apache License 2.0
1.34k stars 523 forks source link

Calendar API NextSyncToken always empty #610

Closed ganySA closed 8 years ago

ganySA commented 8 years ago

I am using a combination of NextSyncToken and NextPageToken.

PageToken seems to work perfectly, but NextSyncToken is empty all the time? See code below:

     Events events;
        String pageToken = null;
        do
        {
            request.PageToken = pageToken;
            events = request.Execute();

            Console.WriteLine(events.Items.Count);
            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    string when = eventItem.Start.DateTime.ToString();
                    if (String.IsNullOrEmpty(when))
                    {
                        when = eventItem.Start.Date;
                    }

                }
            }
            else
            {
                Console.WriteLine("No upcoming events found.");
            }
            pageToken = events.NextPageToken;

        } while (events.NextPageToken != null);

        Console.WriteLine("synch token " + events.NextSyncToken);
        Console.WriteLine("page token " + events.NextPageToken);

The expected behavior is that the synctoken is on the last page however it is null.

ganySA commented 8 years ago

Hi

I have managed to find out why. It seems synch token is broken when using the following option:

        EventsResource.ListRequest request = service.Events.List("primary");
        request.TimeMin = DateTime.Now;
        request.ShowDeleted = true;
        request.SingleEvents = true;
        request.MaxResults = 100;

--> BREAKS --> request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

eric-burel commented 6 years ago

Why is this closed ? Using the orderBy param also breaks js client, but I can't find any documentation about this. If the nextSyncToken is not provided on purpose, this behaviour should at least be clearly documented in the relevant docs.

jskeet commented 6 years ago

The author of the issue closed it themselves. Even if they hadn't, if this is a limitation of the API itself, this repo wouldn't be the right place for the issue to stay open - this repo is for issues in the client libraries themselves.

The documentation does mention not being able to provide orderBy in the same request as a syncToken - it sounds like that documentation needs to be expanded a bit. I can reach out to the Calendar API team to suggest that if you would like me to, but I very much doubt that this is a C# client library issue.

namedgraph commented 5 years ago

@eric-burel it is: https://developers.google.com/calendar/v3/reference/events/list

There are several query parameters that cannot be specified together with nextSyncToken to ensure consistency of the client state.

These are:

  • iCalUID
  • orderBy
  • privateExtendedProperty
  • q
  • sharedExtendedProperty
  • timeMin
  • timeMax
  • updatedMin
ghost commented 4 years ago

As of today, I can confirm that this behavior is still very much implied in the documentation (namely the exceprt from @eric-burel 's post above). I was iteratively paging through a response from an Events list request with an orderBy parameter set. Though using the nextPageToken during iterative paging, the last page of the response did not contain the lastSyncToken.

Eliminating the orderBy parameter (resulting in the default 'unspecified, stable order') resulted in successful return of the lastSyncToken. Hope this helps somebody.