dsteem icon indicating copy to clipboard operation
dsteem copied to clipboard

Missing get_follow_count

Open therealwolf42 opened this issue 8 years ago • 3 comments

SteemJS has the function steem.api.getFollowCount which is missing with dsteem.

I've tried client.database.call('get_follow_count', [ name ] ) but get the following error:

Main Error itr != _by_name.end(): no method with name 'get_follow_count

Would be amazing if you could fix this or tell me if I made a mistake :)

therealwolf42 avatar Nov 05 '17 12:11 therealwolf42

That's because get_follow_count is in a separate api plugin in steemd called follow_api. I want to add a strongly typed helper for this but not sure yet how best to go about it, a lot of calls will change with steemd's new appbase api so I don't want to refactor just yet. For now you can use this:

const response = await client.call('follow_api', 'get_follow_count', ['username'])

jnordberg avatar Nov 08 '17 17:11 jnordberg

client.call('follow_api', 'get_following', ['sweetsssj']).then(console.log)
(node:4249) UnhandledPromiseRejectionWarning: RPCError: a0 != e: too few arguments passed to method
    at Client.<anonymous> (/home/sharon/projects/node/bubot/node_modules/dsteem/lib/client.js:162:23)

edit:

Tried again, this is the code that worked:

client.call('follow_api', 'get_following', ['sweetsssj', '', 'blog', 100])

I tried using 1000 (like the Steemit website does in its ajax post call) but I got RPCError: limit <= 100:

edit2:

There seems to be no pagination, so I can only get the first 100 followers of any account unless I scrape it out of Steemit... I did not realize that when I made this:

const get100 = accountName =>
  client.call('follow_api', 'get_following', [accountName, '', 'blog', 100])

const getAllFollowing = (accountName, accumulator) =>
  !accumulator || accumulator.length % 100 === 0
    ? get100(accountName, accumulator).then(r =>
      getAllFollowing(accountName, accumulator ? accumulator.concat(r) : r))
    : Promise.resolve(accumulator)

getAllFollowing('sweetsssj').then(console.log)

Now I have an array of the first 100 followers over and over...

CryptoSharon avatar Feb 02 '18 02:02 CryptoSharon

Many steemd api's are paged by partial string matching, so passing f starts indexing from e.g. faaaa etc so use the last name you got as the starting for the next page and initial page being an empty string

jnordberg avatar Feb 03 '18 18:02 jnordberg