javascriptgoogle-apibloggergoogle-api-client

Using JS Blogger API v3, How to sort posts in an ascending order?


I'm using Blogger API v3 with Javascript to list a chosen number of posts of a blog.

Problem: I want to list 10 posts from a certain starting date. I'm using startDate parameter to set the start date. The problem is that the first request doesn't return directly the needed posts and I have to use the nextPageToken parameter and make another request to get needed posts (I may need many requests to get needed posts).

Cause:
1- There are more than 10 posts after this starting date.
2- The response become paginated.
3- Those posts are the latest blog posts sorted in a descending order as they match the condition of starting date.

This problem can be solved simply by reverse sorting and it will require then just one request to return the needed posts. So, how can I sort those posts in an ascending order?

gapi.client.blogger.posts.list({
    'blogId': BLOG_ID,
    'maxResults': 10,
    'startDate': "2016-04-05T10:30:00-07:00",
    'orderBy':'published', //
  }).execute(function(response){
    console.log(response.items);
    //those are not the needed posts.
  });

I searched the documentation but not luck. Any ideas?


Solution

  • After I spent almost a day looking for a way to achieve that, I finally decided to change the business a little bit.

    I considered that certain date as an end date and I used parameter endDate instead of startDate to list the latest 10 posts ending with that end date.

    This answer is just as a thought or a work around to help any one in the future and ,hopefully, someone can find this question and conclusively answer it.