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

1 komentar so far

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.


EmoticonEmoticon