Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » A few questions about the scratch apis
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
Is it possible to
1. Find the number of followers I have with the API
2. Find the number of projects I share
thanks
1. Find the number of followers I have with the API
2. Find the number of projects I share
thanks
Last edited by ninjagolloyd (July 21, 2017 17:32:53)
bean
- Wettining
- Scratcher
500+ posts
A few questions about the scratch apis
I know you can get a list of followers (I don't know the url for it though) but I'm not sure about the number of projects shared. Is it possible to
1. Find the number of followers I have with the API
2. Find the number of projects I share
thanks
- Wettining
- Scratcher
500+ posts
A few questions about the scratch apis
I found out how to do both… Is it possible to
1. Find the number of followers I have with the API
2. Find the number of projects I share
thanks
If you go to https://api.scratch.mit.edu/users/(username)/projects and count the ammount of times “id” is said, then you get the ammount of shared projects they have and if you go to https://api.scratch.mit.edu/users/(username)/followers and do the same thing you get the ammount of followers the user has
Last edited by Wettining (July 21, 2017 22:14:20)
- Mrcomputer1
- Scratcher
500+ posts
A few questions about the scratch apis
Both of those are limited to showing 20 projects/followers at a time.I found out how to do both… Is it possible to
1. Find the number of followers I have with the API
2. Find the number of projects I share
thanks
If you go to https://api.scratch.mit.edu/users/(username)/projects and count the ammount of times “id” is said, then you get the ammount of shared projects they have and if you go to https://api.scratch.mit.edu/users/(username)/followers and do the same thing you get the ammount of followers the user has
A solution to that problem would be:
* Use Wettining's method to get part of the project/follower count
* Add ?offset=20 to the URL and repeat Wettining's method (add the number to the project/follower count)
* Increase the offset by 20 until an empty array [] is returned and now the project/follower count will be correct.
My Profile / My User Page / My Talk Page
——————–
Progress bar to 1000+ Posts - Image might not be up to date
——————–
My browser / operating system: Windows NT 10.0 (Windows 11 - 22H2), Firefox 122.0b4
——————–
My ScratchX Extensions——–If you like this post, give me an internet!——–Sharp Scratch Mod
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
okBoth of those are limited to showing 20 projects/followers at a time.I found out how to do both… Is it possible to
1. Find the number of followers I have with the API
2. Find the number of projects I share
thanks
If you go to https://api.scratch.mit.edu/users/(username)/projects and count the ammount of times “id” is said, then you get the ammount of shared projects they have and if you go to https://api.scratch.mit.edu/users/(username)/followers and do the same thing you get the ammount of followers the user has
A solution to that problem would be:
* Use Wettining's method to get part of the project/follower count
* Add ?offset=20 to the URL and repeat Wettining's method (add the number to the project/follower count)
* Increase the offset by 20 until an empty array [] is returned and now the project/follower count will be correct.
bean
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
wait could I add the objects to an array then count the objects?
bean
- nathanprocks
- Scratcher
1000+ posts
A few questions about the scratch apis
The best way that I know of is to just scrape the projects/followers page. Using the API would take a really long time (and hundreds of requests) for some users' follower counts, e.g. griffpatch.
If you want to use the API, something like this should work:
If you want to use the API, something like this should work:
var username = "griffpatch"; var count = 0; function getProjectCount() { var req = new XMLHttpRequest(); req.addEventListener("load", (e) => { let c = JSON.parse(e.target.responseText).length; if (c > 0) { count += c; setTimeout(getProjectCount, 250); console.log(count); } }); req.open("GET", `https://api.scratch.mit.edu/users/${username}/projects?offset=${count}`); req.send(); } getProjectCount();
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
The best way that I know of is to just scrape the projects/followers page. Using the API would take a really long time (and hundreds of requests) for some users' follower counts, e.g. griffpatch.
If you want to use the API, something like this should work:var username = "griffpatch"; var count = 0; function getProjectCount() { var req = new XMLHttpRequest(); req.addEventListener("load", (e) => { let c = JSON.parse(e.target.responseText).length; if (c > 0) { count += c; setTimeout(getProjectCount, 250); console.log(count); } }); req.open("GET", `https://api.scratch.mit.edu/users/${username}/projects?offset=${count}`); req.send(); } getProjectCount();
true, thanks
btw did you mean to use backticks?
bean
- nathanprocks
- Scratcher
1000+ posts
A few questions about the scratch apis
Yes. It's called a template literal. It allows you to include expressions in strings, so instead of doing this: true, thanks
btw did you mean to use backticks?
let name = "Nathan"; let number = 42; console.log("My name is " + name + ". My favourite number is " + number + ".");
let name = "Nathan"; let number = 42; console.log(`My name is ${name}. My favourite number is ${number}.`);
Last edited by nathanprocks (July 22, 2017 16:59:24)
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
oo kewl thanksYes. It's called a template literal. It allows you to include expressions in strings, so instead of doing this: true, thanks
btw did you mean to use backticks?You can use a template literal like this:let name = "Nathan"; let number = 42; console.log("My name is " + name + ". My favourite number is " + number + ".");let name = "Nathan"; let number = 42; console.log(`My name is ${name}. My favourite number is ${number}.`);
bean
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
Last edited by ninjagolloyd (July 22, 2017 17:10:18)
bean
- nathanprocks
- Scratcher
1000+ posts
A few questions about the scratch apis
It would be less efficient to load an entire bloated library just to use AJAX. If you want compatibility with older browsers and IE, there are better libraries for that. would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
okIt would be less efficient to load an entire bloated library just to use AJAX. If you want compatibility with older browsers and IE, there are better libraries for that. would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
bean
- Wettining
- Scratcher
500+ posts
A few questions about the scratch apis
It would be best to just order out what you wanted to be loaded first, second, third, etc. instead of lazy-loading the entire pageokIt would be less efficient to load an entire bloated library just to use AJAX. If you want compatibility with older browsers and IE, there are better libraries for that. would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
- TheUltimatum
- Scratcher
1000+ posts
A few questions about the scratch apis
Best way to do any of this I've found so far is. BeautifulSoup.
- __init__
- Scratcher
1000+ posts
A few questions about the scratch apis
+1. If there isn't an easy way to do something with an API, I use BeautifulSoup. Best way to do any of this I've found so far is. BeautifulSoup.
thisandagain pls explain
- ninjagolloyd
- Scratcher
500+ posts
A few questions about the scratch apis
ohh yeahhhhhhhhh+1. If there isn't an easy way to do something with an API, I use BeautifulSoup. Best way to do any of this I've found so far is. BeautifulSoup.
but there is a way so
bean
- Discussion Forums
- » Advanced Topics
- » A few questions about the scratch apis