What is pagination?
Pagination has long been an issue for me in the Google .net client Library. When the number of results returned by your request is greater then the max results you need to use nextlink in order to get the next set of results.
This has lead to a number of strange hacks for me in the past. We now have an end to that.
I am going to show you a quick example of how this works. It will work with all of the Google APIs and the Google .net Client library, on any method that contains a nextlink and might need pagination. It can be a little tricky getting it to work and setting it up if you have any issues with your favorite API let me know I will see if i can build you an example.
The Code
This is a quick example using the Google Drive API V2.
Note: You are still making additional request to get the next page so watch your quota.
My Thanks
I would like to thank Jon Skeet for his efforts in adding pagination to the client library. You can read my feature request here. pagination #632
Hi Linda,
Can you clarify where we get the PageStreamer class from? Is it part of any nuget package (drive v2 or v3)? It looks like Job pushed the changes, but those haven’t made it to an official release yet. Does that mean that for the time being we should copy the PageStreamer from the commit https://github.com/jskeet/google-api-dotnet-client/commit/2bdb9b8b7d08735be142e27858530d9c46f17b98 ?
Thanks.
PageStreamer if memory serves is part of Google.Apis and yes if you import any of the API NuGet packages they will automatically grab Google.APIs (Google.Apis.Drive.V2 || Google.Apis.Drive.V3).
Yes it was release a while ago one of those stealth releases that the team is becoming very good at. I really need to get on them about creating actual change log release announcements.
Note: If you are running a project with Framework 4.0 then you probably wont have this it was probably released some where around version 1.12 and support for Framework 4.0 stopped at 1.10. In that case yes you can just grab the PageStreamer method and add it to your project manually it “should” work.
Hi Linda,
thank you very much for your Pagination Solution. I found your article and started to use it immediatly. It works perfect for me now. I use the Calendar API v3 and I face one problem:
I do a full sync of all Events of a particular google calendar with about 7000 entries to a SQL-Server-Database.
After I received the last entry, I expect to get also the “nextSyncToken” Property in the eventsList-Result.
But it is always null.
Any toughts?
Thanks in advance.
Kind regards
Andreas