Steem API Guide - How To Get Recent Posts(getDiscussionsByCreated) and Load More
Steem platform's lack of documentation frustrates third-party developers.
I've spent couple of days to figure this out. As I am posting the secret, you don't have to waste too much time on it.
I'll talk about Steem API get_discussions_by_created The real usage currently hidden in the document.
Language: JavaScript
Dependency: Steem.js
How to get recent 10 posts in a tag
<script src="./steem.min.js"></script>
<script>
var oldestPermLink = ""
steem.api.getDiscussionsByCreated({"tag": "kr", "limit": 10}, function(err, result) {
if (err === null) {
var i, len = result.length;
for (i = 0; i < len; i++) {
var discussion = result[i];
console.log(i, discussion);
}
} else {
console.log(err);
}
});
</script>
limit range: 1 ~ 100 (a number greater than 100 will be reject by steemd)
So far, it's easy as it is "documented" but below is the secret
How to get the next 10 posts in the tag
<script src="./steem.min.js"></script>
<script>
steem.api.getDiscussionsByCreated({"tag": "kr", "limit": 10}, function(err, result) {
if (err === null) {
var i, len = result.length;
for (i = 0; i < len; i++) {
var discussion = result[i];
console.log(i, discussion);
// Store the last permlink and author
if (i == len - 1) {
window.permlink = discussion.permlink;
window.author = discussion.author;
}
}
} else {
console.log(err);
}
});
....
//In the load more button click event,
steem.api.getDiscussionsByCreated({"tag": "kr", "limit": 10, "start_permlink": window.permlink, "start_author": window.author}, function(err, result) {
// now result has the next 10 posts
}
</script>
Secret
The secret is start_permlink and start_author.
You have to give both of these "optional parameter"
That will give you the posts list starting from that post and older posts as many as limit
So there will be a redundant post. So you may have to implement your own logic to ignore the redundant post.
At least, the secret is now revealed...