Session ID Guide¶
What is session ID?
Sesssion ID is a type of cookie value that is set by the Scratch website on your local computer
The website uses the Session ID as a type of security check, i.e, for example, if you follow a user or post a comment, the Scratch website first checks if the session ID of your account is correct and then allows you to perform that action
The Scratch API not only uses the session ID to validate/check the requests but also certain other cookie values which are equally important as the session ID but the ScratchConnect library requires only the session ID using which it fetches the other cookie types!
Note: The session ID automatically changes (maybe sometimes) when you login to the Scratch website
Steps to get the Session ID¶
Following are the 2 ways using which you can get the session ID of your account:
Using the Python Code¶
You can login using ScratchConnect locally on your computer, using the code below:
import scratchconnect
# Replace the placeholders below with you actual Scratch information
session = scratchconnect.ScratchConnect("Username", "Password")
with open("session_id.txt", "w") as file:
file.write(session.session_id) # Write the session ID in a text file called "session_id.txt"
# You can open the text file and read/copy the session ID
From your browser¶
Follow the steps:
(It is advised to follow only the steps below when you open the developer tools to keep your account secure, if you don't know what you're doing. Remember: Never share your session ID with anyone!)
- Login to the Scratch website
- Open the developer tools by right clicking anywhere on the page and by clicking the "Inspect" option. You can open the developer tools on
Windows
OS using the shortcutControl + Shift + C
and onMac
OS using the shortcutCommand + Option + C
depending on your browser -
Once you're done, follow the steps according to your browser:
For
Firefox
browser:Click the
Storage
tab; In theCookies
section click the Scratch website's name. There you will find a key with the name asscratchsessionsid
. Copy the value corresponding value to that key. This is your session IDImage (The cookie values are censored(in red) for security):
For
Chrome
browser:Click the
Application
tab; In theStorage
section, click theCookies
option and then the Scratch website's name. There you will find a key with the name asscratchsessionsid
. Copy the value corresponding value to that key. This is your session IDImage (The cookie values are censored(in red) for security):
Final Important Note¶
The session ID is very important. Do NOT share it with anyone.
Also, remember to store the session ID in environment
variables if you are using/running the code in online IDEs like replit!
While sharing your code, make sure that you remove the sensitive information from your file!