0

I am looking to find the follower count of a Scratch user using the Scratch API. I already know how to get their message count, with https://api.scratch.mit.edu/users/[USER]/messages/count/.

VFDan
  • 831
  • 10
  • 26
  • 1
    I wanted to add a [scratch-api] tag, but it does not exist and I do not have the privileges to create it. If anybody with 1500+ reputation is seeing this, please make the tag and inform me of it by replying to this comment. – VFDan Apr 24 '19 at 21:33

6 Answers6

1

This answer targets the Scratch REST API, documented here.

You get the user's followers by requesting them: https://api.scratch.mit.edu/users/some_username/following where some_username is to be replaced by the actual username.

This will return 0 to 20 results (20 is the default limit of objects returned by the REST API). If there's less than 20 results, then you're done. The amount of followers is simply the count of the objects returned.

If there's 20 objects returned, we can't be certain we've requested all the user's friends as there might be more to come. Therefore, we skip the first 20 followers of that user by supplying the ?offset= parameter: https://api.scratch.mit.edu/users/some_username/following?offset=20

This retrieves the second 'page' of friends. Now we simply loop through the procedure described above, incrementing offset by 20 each time until either less than 20 results are returned or no results are returned. The amount of friends of that user is the cumulative count of the objects returned.

Zimano
  • 1,870
  • 2
  • 23
  • 41
0

As mentioned by _nix on this forum thread, there is currently no API to achieve this. However, he/she rightly points out that the number can be obtained from a user's profile page.

You may write a script (in JavaScript, for example) to parse the HTML and get the follower count in the brackets at the top of the page.

Hope this helps!

  • Thank you. I was trying not to go down that path but I guess I have to. – VFDan Apr 25 '19 at 20:57
  • Well, it doesn't allow me to do it, because of cross-origin framing. – VFDan Jul 27 '19 at 23:31
  • Ah, I didn't realise that. I can't think of any other way to do it at the moment but I'll be sure to tell you if I figure something out. Do tell me if you find a workaround yourself. I'll be interested to know how it was achieved! –  Jul 30 '19 at 04:18
  • Well, I made a topic in the discussion forums: https://scratch.mit.edu/discuss/topic/351268/ – VFDan Jul 30 '19 at 16:15
  • 1
    Wait a second, there may be a way in Python. I'll edit if there is. **Edit: Found it! https://pastebin.com/LnaA25S9** – VFDan Jul 30 '19 at 16:21
  • Fantastic! I'll definitely try the Python solution when I get a chance to. Glad you figured it out! –  Aug 01 '19 at 04:14
  • I can't take the credit, it should go to https://github.com/12944qwerty. He wrote the code, and I just put it on Pastebin. – VFDan Aug 02 '19 at 00:41
0

There is a solution in Python:

import requests
import re
def followers(self,user):
   followers = int(re.search(r'Followers \(([0-9]+)\)', requests.get(f'https://scratch.mit.edu/users/{user}/followers').text, re.I).group(1))
   return f'{followers} on [scratch](https://scratch.mit.edu/users/{user}/followers)'

Credit goes to 12944qwerty, in his code (adapted to remove some implementation specific stuff).

VFDan
  • 831
  • 10
  • 26
0

use ScratchDB

var user = "username here";
fetch(`https://scratchdb.lefty.one/v3/user/info/${user}`).then(res => res.json()).then(data => {
    console.log(`${user} has ` + data["followers"].toString() + " followers");
}

(Edit: this is javascript btw, I prefer Python but Python doesn't have a cloud.set function and this is how I did it)

GHOST
  • 337
  • 3
  • 9
0

Use ScratchDB (I used httpx, but you can GET with anything):

import httpx
import json

user = "griffpatch"

response = httpx.get(f"https://scratchdb.lefty.one/v3/user/info/{ user }")
userData = json.loads(response.text)

followers = userData["statistics"]["followers"]
Gugalcrom123
  • 101
  • 1
  • 9
-1

https://api.scratch.mit.edu/users/griffpatch/followers

this gives the follower names, scratch staus(scratch team or not), pfp, everything in their profile

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 30 '21 at 15:57