[STEEMIT API] How to retrieve feed

in #steemit7 years ago


Source

Hi Steemians!

This will be a little post that might save developers a bunch of their time.

As many of you already know, me and @lino are the creators of the upcoming platform @gaamit dedicated to game developers, so we are leveraging Steemit API's to interact with the blockchain.

Steemit API's work very well, but the documentation is quite scarce. One of the basic tasks we had to accomplish is getting, for instance, the feed coming from the "new" section of a particular tag ("gamedev" in our case).

Using steem-js we first tried with getState:

steem.api.getState('/created/gamedev', function(err, result) {
    console.log(err, result);
});

First thing to notice: "created" stands for "new" category. This call goes fine, but there is no way of retrieving a certain amount of posts from here. We need something more specific.

Get Discussions By Created (straight from the docs) seems the correct one:

steem.api.getDiscussionsByCreated(query, function(err, result) {
  console.log(err, result);
});

Cool! But, wait.. what "query" parameter stands for? We haven't managed to find a documentation about this parameter, but in the examples folders from the GitHub account we managed to find something (server.js):

steem.api.getDiscussionsByActive({
  limit: 10,
  start_author: 'thecastle',
  start_permlink: 'this-week-in-level-design-1-22-2017'
}, function(err, result) {
    console.log(err, result);
});

So now we know something about that "query" parameter. Last thing we need is a way to get feed from "gamedev" tag. We guessed that "tag" would have worked, so we tried it.. and indeed it worked.

So, the ultimate call is the following:

steem.api.getDiscussionsByCreated({
  limit: 10,
  start_author: 'thecastle',
  start_permlink: 'this-week-in-level-design-1-22-2017',
  tag: 'gamedev'
}, function(err, result) {
    console.log(err, result);
});

Where:

  • limit stands for the number of posts to retrieve
  • start_author is the author of the last post we want to start from (you must specify also start_permlink!)
  • start_permlink is the permlink of the last post we want to start from (you must specify also start_author!)
  • tag will be "gamedev" in our case

You can use the same format for getDiscussionsByHot and getDiscussionsByTrending.

Let me know if you can point out some good resources about this topic, so we can share them with the community

Thanks for reading!

Sort:  

good information shared.....

I could use more of these types of how to guides. Thanks for sharing.

Congratulations @mikepicker! You have received a personal award!

Happy Birthday - 1 Year on Steemit Happy Birthday - 1 Year on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.

For more information about this award, click here

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @mikepicker! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Sorry for the query, as I am a newbie on this but how can you pass the output/result to a variable? I am trying to pass the value of a specific property to a variable.

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.030
BTC 60023.73
ETH 3191.15
USDT 1.00
SBD 2.45