I wanted to get the list of the users following me that I also follow. This is a script I made to accomplish that. You're free to add to it :)
function getReciprocalFollowers (username) {
/**
* Get reciprocal followers of a user
* @param {String} username - username of the new account
* @return {Array} reciprocal usernames
*/
return new Promise(function(resolve, reject) {
steem.api.getFollowers(username,
'',
'blog',
1000,
function(err, result) {
var reciprocal = [];
result.forEach(function(e) {
var getFollowing = new Promise(function(resolve, reject) {
steem.api.getFollowing(username,e.follower,'blog',1,
function(err, r) {
if (r[0] && e.follower == r[0].following)
resolve(r[0].following);
resolve(null);
});
});
getFollowing.then(function(e) {
if (e)
reciprocal.push(e);
});
});
resolve(reciprocal);
});
});
}
So first we call the getFollowers Api to get our followers, the "1000" is the max number of followers. In my case I hardcoded it to 1000, but it could be more or you could loop if you have millions of followers.
Then for each of these followers, we try to find if that follower follows us. If yes, we resolve with the username, else we resolve with null.
The promise returns the username that we push to an array.
The array is then returned to the caller of getReciprocalFollowers() in the form of a promise.
How to call method
function Main() {
getReciprocalFollowers('julienbh').then(function(e) {
console.log(e);
});
}
Since we have a promise, we need to use the then pattern. Here I just log to the console the array of users, but you can now do what you want with this :)
Julie xx
Posted on Utopian.io - Rewarding Open Source Contributors