Discuss Scratch

-Snipet-
Scratcher
500+ posts

Scratch API get Total Follower Count

Basically what the title says. I know how to get the followers of a particular user, but it just shows a few. How do I get the total amount?
_nix
Scratcher
1000+ posts

Scratch API get Total Follower Count

There is no API for this (though they might add one eventually). For now the only way to get the follower count of a user is to parse the HTML to find the number on the user's /followers/ page.
-Snipet-
Scratcher
500+ posts

Scratch API get Total Follower Count

_nix wrote:

There is no API for this (though they might add one eventually). For now the only way to get the follower count of a user is to parse the HTML to find the number on the user's /followers/ page.
Oh yeah. I completely overlooked that. Thanks!

Last edited by -Snipet- (March 24, 2019 18:18:38)

-Bonfire-
Scratcher
59 posts

Scratch API get Total Follower Count

-Snipet- wrote:

_nix wrote:

There is no API for this (though they might add one eventually). For now the only way to get the follower count of a user is to parse the HTML to find the number on the user's /followers/ page.
Oh yeah. I completely overlooked that. Thanks!
You could make one yourself
Movies22_by_TR
Scratcher
19 posts

Scratch API get Total Follower Count

_nix wrote:

There is no API for this (though they might add one eventually). For now the only way to get the follower count of a user is to parse the HTML to find the number on the user's /followers/ page.
well, i tried doing that using node-fetch, but i got a empty response:
<html><head></head><body></body></html>
. How can i parse the HTML then?
_nix
Scratcher
1000+ posts

Scratch API get Total Follower Count

Movies22_by_TR wrote:

_nix wrote:

There is no API for this (though they might add one eventually). For now the only way to get the follower count of a user is to parse the HTML to find the number on the user's /followers/ page.
well, i tried doing that using node-fetch, but i got a empty response:
<html><head></head><body></body></html>
. How can i parse the HTML then?
Huh, that's really weird! It definitely didn't error like that for me in the past, and looking at the code for other libraries for interfacing with Scratch, I don't see anything different. (I tested myself and got the same response.)

Apparently api.scratch.mit.edu still works fine, so you could try using that. It (still) doesn't have a follow count directly accessible anywhere, but you can calculate it by making repeated requests at different follower offsets to narrow in on the precise count.

E.g, make a number of requests like this:

  1. https://api.scratch.mit.edu/users/_nix/followers/?offset=0&limit=40
    Response array length is full (40 items, max length for API) so there are more than 40 followers.
  2. https://api.scratch.mit.edu/users/_nix/followers/?offset=40&limit=40
    Length is 40 so there are more than 80 followers.
  3. https://api.scratch.mit.edu/users/_nix/followers/?offset=80&limit=40
    Length is 40 so there are more than 120 followers.
  4. https://api.scratch.mit.edu/users/_nix/followers/?offset=160&limit=40
    Length is 40 so there are more than 180 followers.
  5. https://api.scratch.mit.edu/users/_nix/followers/?offset=320&limit=40
    Length is 40 so there are more than 360 followers.
  6. https://api.scratch.mit.edu/users/_nix/followers/?offset=640&limit=40
    Length is 0 so there are less than 640 followers—we've overshot, so start counting down. Halfway between 360 and 640 is 500…
  7. https://api.scratch.mit.edu/users/_nix/followers/?offset=500&limit=40
    Length is 40 so there are more than 540 followers. Just count up from here since we must be pretty close.
  8. https://api.scratch.mit.edu/users/_nix/followers/?offset=540&limit=40
    Length is 8 so there are precisely 540 + 8 = 548 followers.

…Okay, so, 548 is more than what it says on my profile, but it is exactly what is shown when I delete my account (“You joined the Scratch community 5 years ago. You've created 907 projects and have 548 followers.”), so yaknow (I think deleted accounts are included? I haven't researched this carefully.)

I definitely didn't use the most generally efficient algorithm here, but in general this will always take at least a few requests (more for accounts with more followers), so make sure you're appropriately rate limiting yourself (like only making 5 requests a second for example). Otherwise you risk getting in trouble for overloading the Scratch APIs.

Last edited by _nix (Jan. 2, 2022 19:47:45)

mybearworld
Scratcher
1000+ posts

Scratch API get Total Follower Count

ScolderCreations
Scratcher
1000+ posts

Scratch API get Total Follower Count

mybearworld wrote:

That makes sense, the reason is probably to prevent bots from spamming those pages with requests.
Movies22_by_TR
Scratcher
19 posts

Scratch API get Total Follower Count

_nix wrote:

Movies22_by_TR wrote:

_nix wrote:

There is no API for this (though they might add one eventually). For now the only way to get the follower count of a user is to parse the HTML to find the number on the user's /followers/ page.
well, i tried doing that using node-fetch, but i got a empty response:
<html><head></head><body></body></html>
. How can i parse the HTML then?
Huh, that's really weird! It definitely didn't error like that for me in the past, and looking at the code for other libraries for interfacing with Scratch, I don't see anything different. (I tested myself and got the same response.)

Apparently api.scratch.mit.edu still works fine, so you could try using that. It (still) doesn't have a follow count directly accessible anywhere, but you can calculate it by making repeated requests at different follower offsets to narrow in on the precise count.

E.g, make a number of requests like this:

  1. https://api.scratch.mit.edu/users/_nix/followers/?offset=0&limit=40
    Response array length is full (40 items, max length for API) so there are more than 40 followers.
  2. https://api.scratch.mit.edu/users/_nix/followers/?offset=40&limit=40
    Length is 40 so there are more than 80 followers.
  3. https://api.scratch.mit.edu/users/_nix/followers/?offset=80&limit=40
    Length is 40 so there are more than 120 followers.
  4. https://api.scratch.mit.edu/users/_nix/followers/?offset=160&limit=40
    Length is 40 so there are more than 180 followers.
  5. https://api.scratch.mit.edu/users/_nix/followers/?offset=320&limit=40
    Length is 40 so there are more than 360 followers.
  6. https://api.scratch.mit.edu/users/_nix/followers/?offset=640&limit=40
    Length is 0 so there are less than 640 followers—we've overshot, so start counting down. Halfway between 360 and 640 is 500…
  7. https://api.scratch.mit.edu/users/_nix/followers/?offset=500&limit=40
    Length is 40 so there are more than 540 followers. Just count up from here since we must be pretty close.
  8. https://api.scratch.mit.edu/users/_nix/followers/?offset=540&limit=40
    Length is 8 so there are precisely 540 + 8 = 548 followers.

…Okay, so, 548 is more than what it says on my profile, but it is exactly what is shown when I delete my account (“You joined the Scratch community 5 years ago. You've created 907 projects and have 548 followers.”), so yaknow (I think deleted accounts are included? I haven't researched this carefully.)

I definitely didn't use the most generally efficient algorithm here, but in general this will always take at least a few requests (more for accounts with more followers), so make sure you're appropriately rate limiting yourself (like only making 5 requests a second for example). Otherwise you risk getting in trouble for overloading the Scratch APIs.
Well, there is no way to do it easly/fast. Because i was working in a live followers counter and I needed to get the followers count of every second.
god286
Scratcher
1000+ posts

Scratch API get Total Follower Count

Movies22_by_TR wrote:

Well, there is no way to do it easly/fast. Because i was working in a live followers counter and I needed to get the followers count of every second.
Webscraping could be an option.
document.querySelector(".box-head > h2:nth-child(2)").innerText // me » Followers (12345)"
Wetbikeboy2500
Scratcher
100+ posts

Scratch API get Total Follower Count

god286 wrote:

Movies22_by_TR wrote:

Well, there is no way to do it easly/fast. Because i was working in a live followers counter and I needed to get the followers count of every second.
Webscraping could be an option.
document.querySelector(".box-head > h2:nth-child(2)").innerText // me » Followers (12345)"

This is for the top of the followers page where it displays the total number of followers a user has. This makes it a single request.

You can then use some regex on it to extract the specific number

/\((\d+)\)/g.exec(document.querySelector('.box-head h2').innerText)[1]



Last edited by Wetbikeboy2500 (Jan. 4, 2022 19:58:31)

coolcoder1213
Scratcher
100+ posts

Scratch API get Total Follower Count

ScratchDB offers the stats for the amount of followers you have but not the amount. You would have to web-scrape.
MagicCrayon9342
Scratcher
1000+ posts

Scratch API get Total Follower Count

NFlex23
Scratcher
1000+ posts

Scratch API get Total Follower Count

MagicCrayon9342 wrote:

(#13)
You can simply grab it from the api directly. Using a CORS proxy.

Here's a list of them

A list inside a list.
Always online, fast, and free. I literally never update it, its just as cors-anywhere instance which you CAN host yourself.
I don't think you read the OP carefully. You don't even need a proxy for the Scratch API anyway.
MagicCrayon9342
Scratcher
1000+ posts

Scratch API get Total Follower Count

NFlex23 wrote:

MagicCrayon9342 wrote:

(#13)
You can simply grab it from the api directly. Using a CORS proxy.

Here's a list of them

A list inside a list.
Always online, fast, and free. I literally never update it, its just as cors-anywhere instance which you CAN host yourself.
I don't think you read the OP carefully. You don't even need a proxy for the Scratch API anyway.
You can do it manually but a CORS proxy is just easier.

From a website you WILL need a CORS proxy or that manual method.
Steve0Greatness
Scratcher
1000+ posts

Scratch API get Total Follower Count

ScratchDB has a page for this:
https://scratchdb.lefty.one/v3/user/info/:user
this returns a JSON of info about the user in question. The total follower count is under the keys statistics, then followers.
MagicCrayon9342
Scratcher
1000+ posts

Scratch API get Total Follower Count

Steve0Greatness wrote:

ScratchDB has a page for this:
https://scratchdb.lefty.one/v3/user/info/:user
this returns a JSON of info about the user in question. The total follower count is under the keys statistics, then followers.
To clear some confusion, if you ever see a ‘:’ before a value in a URL of an express application that means that's a value to replace with the ‘user’ in this case. Not sure why everyone includes the colon as its only necessary in the code itself. Confused me at one point.
NFlex23
Scratcher
1000+ posts

Scratch API get Total Follower Count

MagicCrayon9342 wrote:

(#17)

Steve0Greatness wrote:

ScratchDB has a page for this:
https://scratchdb.lefty.one/v3/user/info/:user
this returns a JSON of info about the user in question. The total follower count is under the keys statistics, then followers.
To clear some confusion, if you ever see a ‘:’ before a value in a URL of an express application that means that's a value to replace with the ‘user’ in this case. Not sure why everyone includes the colon as its only necessary in the code itself. Confused me at one point.
It's to show people that you replace it with an arbitrary value. If you didn't include the colon it would be even more confusing.

Powered by DjangoBB