Skip to content

Instantly share code, notes, and snippets.

@EDDxample
Created January 1, 2023 22:29
Show Gist options
  • Save EDDxample/c0e631df7ffdb965913a826c481adaa7 to your computer and use it in GitHub Desktop.
Save EDDxample/c0e631df7ffdb965913a826c481adaa7 to your computer and use it in GitHub Desktop.
Script to fetch minecraft player data from its nickname
import base64
import json
import requests
def get_uuid(nickname: str) -> str:
"""
Response Body:
{
"name":"EDDxample",
"id":"519e666052d64bf39a34ce7246796d2e"
}
"""
response = requests.get(f'https://api.mojang.com/users/profiles/minecraft/{nickname}')
data = response.json()
uuid = data['id']
return uuid
def get_profile(uuid: str) -> dict:
"""
Response Body:
{
"id": "519e666052d64bf39a34ce7246796d2e",
"name": "EDDxample",
"properties": [{
"name": "textures",
"value": "base64-encoded object"
}]
}
Decoded Object:
{
"timestamp": 0,
"profileId": "519e666052d64bf39a34ce7246796d2e",
"profileName": "EDDxample",
"textures": {
"SKIN": {
"url": "..."
},
"CAPE": {
"url": "..."
}
}
}
"""
response = requests.get(f'https://sessionserver.mojang.com/session/minecraft/profile/{uuid}')
data = response.json()
encoded_profile = data['properties'][0]['value']
profile = json.loads(base64.b64decode(encoded_profile))
return profile
if __name__ == '__main__':
nickname = 'notch'
uuid = get_uuid(nickname)
profile = get_profile(uuid)
print(profile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment