Tuesday, October 3, 2017

Implementing Load More When Woking On Blogger's API



In this tutorial, i will share a tutorial about how to implementing load more and pagination function in Blogger API using retrofit.

When you working with API Blogger, you will face an endpoint that contains much data in list.

The URL that contains a lot of data in list is :
https://www.googleapis.com/blogger/v3/blogs/your-id-blog/posts?key=YOUR_AUTH_ID
That URL will display output json look like the following image :

Output List Json

If you run the URL above, the result will give you only 10 datas in first page. Take a look at attribute items.

To get the next page you have to request it again (load more) and display the result as pagination. To implementing the pagination (request the next page), you can use the attribute nextPageToken. As long as the attribute nextPageToken exist, it means the data still exist in the next page.

Request the first page


Just request the first data in normal URL (without params nextPageToken). In this case i request the data using retrofit :

On the code above, I request the first page and set the data into the adapter. Don't forget to save the value of nextPageToken.

In load more function, i check the nextPageToken is exist or not. Is exist, then request the next page.

Request the next page


To request the next page, you have to add params pageToken, and the value set from nextPageToken.

The URL to be :
https://www.googleapis.com/blogger/v3/blogs/your-id-blog/posts?key=YOUR_AUTH_ID&pageToken=CgkIChjigf_aoisQu_ugxZqtye83
The code is look like the follows :


That's all what i did to implementing load more pagination when request data using Blogger API. Hope it helps. Thank you.

Related Posts

3 komentar

I'm unable to get next Page token what should i do ? it visible in json format in google chrome, but in android it return null pointer exception while running app at first time.

When working with the Blogger API, a large number of posts cannot always be displayed in a single request. Instead, the API returns the posts in pages and provides a nextPageToken when additional results are available. This makes it possible to implement a “Load More” feature that retrieves the next set of posts without loading everything at once. The application can store the returned token and send it back as the pageToken parameter when requesting the next page.Data Visualization Course. This approach is useful for improving the user experience when displaying large lists of Blogger posts. In this article, we’ll explore how to implement a Load More and pagination feature using the Blogger API and how to handle the next page of results efficiently.


EmoticonEmoticon