Authentication¶
To authenticate our client, we need our .ROBLOSECURITY token. To learn about why we need this and how to get it, please see ROBLOSECURITY.
Once we have our token, we can add it to our client by passing it as the first parameter.
Use the following code and replace TOKEN
with the .ROBLOSECURITY token grabbed earlier to authenticate your client.
from roblox import Client
client = Client("TOKEN")
To test your token, replace the code in main()
with the following:
user = await client.get_authenticated_user()
print("ID:", user.id)
print("Name:", user.name)
Using a .env file¶
To solve this problem, we'll create a separate file called .env
which will contain our token.
Your file should look like this, where TOKEN is the .ROBLOSECURITY token you grabbed earlier.
.env
Place it in the same folder as your application's main file.
ROBLOXTOKEN=TOKEN
Your file structure should look like this:
.
├─ .env
└─ main.py
Next, install the python-dotenv library with the following command:
$ pip install python-dotenv
import os
from dotenv import load_dotenv
load_dotenv()
client = Client(os.getenv("ROBLOXTOKEN"))
get_authenticated_user
and you should be all set!
Finished code
main.py
import asyncio
import os
from dotenv import load_dotenv
from roblox import Client
load_dotenv()
client = Client(os.getenv("ROBLOXTOKEN"))
async def main():
user = await client.get_authenticated_user()
print("ID:", user.id)
print("Name:", user.name)
asyncio.get_event_loop().run_until_complete(main())