SandCastleIcon.png This article documents something which is not associated with Scratch, the Lifelong Kindergarten Group, or the Massachusetts Institute of Technology.

This tutorial teaches how to access the Scratch API using Python 3.

Note Warning: Using this to make bots that perform social actions (loving, following, commenting, etc.) violates the Terms of Use and may result in a ban. Please use this appropriately.

Setup

To access Scratch using Python 3, an IDE for Python 3 is needed. Install the module "scratchclient", made by Raihan142857 to access Scratch. Do this by going into a terminal or Command Prompt and typing pip install scratchclient. This should download the correct module to access Scratch. Lastly, make sure your device is connected to the internet.

Coding

Once it has been setup, the programming can begin.

Note Note: For the functions to display information, such as: session.get_project(PROJECTIDHERE).get_comments()[0].content You may need to use the "print" function to display the information in your console. Like so: print(TEXT). For example, if you want to get a comment, you would use: print(session.get_project(PROJECTIDHERE).get_comments()[0].content).

Follow this script very carefully:

  1. Import the ScratchSession module with this script: from scratchclient import ScratchSession
  2. Login with one's username and password with this script: session = ScratchSession("username", "password")
  3. Use the functions below.

Here is a script of the basic things to do (comments have a hashtag (#) before them; they are not actual code, but notes for clarity):

from scratchclient import ScratchSession

session = ScratchSession("username", "password") #enter account's credentials

Comments

session.get_project(PROJECTIDHERE).post_comment("COMMENTTEXTHERE") #to post comments on projects
session.get_studio(STUDIOIDHERE).post_comment("COMMENTTEXTHERE") #to post comments on studios
session.get_studio(USERNAMEHERE).post_comment("COMMENTTEXTHERE") #to post comments on profiles
session.get_project(PROJECTIDHERE).get_comments()[0].content #To get comments

Cloud Variables

connection = session.create_cloud_connection(PROJECTIDHERE) #To create a cloud connection (must be done first)
connection.set_cloud_variable("VARIABLENAMEHERE", "VALUEHERE") #To set a cloud variable
connection.get_cloud_variable("VARIABLENAMEHERE") #To get a cloud variable

Projects

session.get_project(PROJECTIDHERE).love() #to love a project
session.get_project(PROJECTIDHERE).favorite() #to favorite a project
session.get_project(PROJECTIDHERE).unlove() #to unlove a project
session.get_project(PROJECTIDHERE).unfavorite() #to unfavorite a project
session.get_project(PROJECTIDHERE).description #To get project description
session.get_project(PROJECTIDHERE).instructions #To get a project instructions
session.get_project(PROJECTIDHERE).title #To get the title of a project
session.get_project(PROJECTIDHERE).love_count #To get the amount of loves for a project
session.get_project(PROJECTIDHERE).favorite_count #To get the amount of favorites for a project
session.get_project(PROJECTIDHERE).remix_count #To get the amount of remixes for a project
session.get_project(PROJECTIDHERE).view_count #To get the amount of views for a project
session.get_project(PROJECTIDHERE).comments_allowed #To see if the project allows comments
session.get_project(PROJECTIDHERE).author.username #To see the creator of the project

Studios

Document.png Please expand this section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2021)

session.get_studio(STUDIOIDHERE).description #To get studio description
session.get_studio(STUDIOIDHERE).title #To get the studio title
session.get_studio(STUDIOIDHERE).host #To get the user id of host of the studio
session.get_studio(STUDIOIDHERE).visible #To see if the studio is deleted or not
session.get_studio(STUDIOIDHERE).open_to_public #To see if anyone can add projects
session.get_studio(STUDIOIDHERE).comments_allowed #To see if comments are allowed
session.get_studio(STUDIOIDHERE).thumbnail_URL #To get the URL of the studio thumbnail
session.get_studio(STUDIOIDHERE).created_timestamp #To get the timestamp of when the studio was created
session.get_studio(STUDIOIDHERE).last_modified_timestamp #To get the timestamp of when the studio was last modified
session.get_studio(STUDIOIDHERE).curator_count #To get the amount of curators
session.get_studio(STUDIOIDHERE).follower_count #To get the amount of followers
session.get_studio(STUDIOIDHERE).manager_count #To get the amount of managers
session.get_studio(STUDIOIDHERE).add_project(PROJECTIDHERE) #To add a project to the studio
session.get_studio(STUDIOIDHERE).remove_project(PROJECTIDHERE) #To remove a project from the studio
session.get_studio(STUDIOIDHERE).get_projects(all=True) #To get all projects in the studio
session.get_studio(STUDIOIDHERE).get_curators(all=True) #To get all curators
session.get_studio(STUDIOIDHERE).get_managers(all=True) #To get all managers
session.get_studio(STUDIOIDHERE).follow() #Follows the studio
session.get_studio(STUDIOIDHERE).unfollow() #Unfollows the studio
session.get_studio(STUDIOIDHERE).open_to_public() #Makes it so any can add projects to the studio
session.get_studio(STUDIOIDHERE).close_to_public() #Makes it so only curators and mangers can add projects to the studio
session.get_studio(STUDIOIDHERE).toggle_commenting() #Toggles the commenting on and off
session.get_studio(STUDIOIDHERE).invite_curator(USERTOBEINVITED) #Invites a user
session.get_studio(STUDIOIDHERE).promote_curator(CURATORTOBEPROMOTED) #Promotes curator
session.get_studio(STUDIOIDHERE).set_title(TITLENAME) #Sets the title
session.get_studio(STUDIOIDHERE).delete() #Deletes the studio

Users

session.get_user(USERNAMEHERE).get_message_count() #To get a message count of a user
session.get_user(USERNAMEHERE).follow() #to follow a user
session.get_user(USERNAMEHERE).unfollow() #to unfollow a user
session.get_user(USERNAMEHERE).profile.bio #To get the About Me from a specified user
session.get_user(USERNAMEHERE).get_followers()[0].username #To get the users followers
session.get_user(USERNAMEHERE).joined_timestamp #To get the ISO timestamp of when the user joined
session.get_user(USERNAMEHERE).scratchteam #To get a boolean (true/false) of whether the user is a member of the Scratch Team

Miscllaneous

Document.png Please expand this section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2021)

session.get_news()[0].title #To get the title of a news in the Scratch News section

External Links

Cookies help us deliver our services. By using our services, you agree to our use of cookies.