steemit/steem-js

How to get posts from people I follow?

Closed this issue · 3 comments

Hi guys,
I'm about to graduate. I'm developing a project about blockchain and Steemit.

I'm trying to find a way to get posts from users I follow. I've tried to use this method, but without any success. I'd like to put in the tag field 'USERNAME' a list of users, not only one username. Can someone help me?

Thank you in advance!!!

The method is :
var ul = document.getElementById('result');
var query = {
tag: USERNAME,
limit: 100
};
steem.api.getDiscussionsByFeed(query, function (err, discussions) {
//console.log(err, discussions);
if (!err) {
discussions.map(function (discussion) {
var li = document.createElement('li');
li.innerHTML = discussion.title;
ul.appendChild(li);
});
}
});

steem.api.getDiscussionsByFeed already gets the posts from users you follow if you put the username as your own.

const query = {tag: 'pjau', limit: 100};
steem.api.getDiscussionsByFeed(query, (err, response) => {
    console.log(err, response);
});

You would need to filter it though, because it includes reblogs. Below will do that, but it will also remove any you follow if someone else you follow reblogs them. lol

response.forEach((r) => {
    // remove any that are reblogs
    if (r.reblogged_by.length == 0) {
        console.log(r);
    }
}); 

Other than that, I have no idea, maybe create an array of the accounts you want and filter out them from it?

const accounts = ['isnochys','arcange'];
const query = {tag: 'pjau', limit: 100};
steem.api.getDiscussionsByFeed(query, (err, response) => {
    if (response) {
        response.forEach((r) => {
            // remove any that are not in the accounts array
            if (accounts.includes(r.author)) {
                console.log(r);
            }
        });
    }
});

There's probably any easier way, but I don't know of it. But hopefully this helps.

Thank you Paul for your suggestions: i've tried to use your code, but whitout any success.
I can't be able to get back on my web page the posts' list...