Hello Forums,
I am using the tracker gg API to try and get a CSGO player’s profile stats. I believe I have done everything correctly but am receiving a 401 response code. I have copied my API key into my .env and assigned it as a variable in my code using: TRACKER_GG = os.getenv('TRACKERGG')
. Here is my full code, any ideas of what I may be doing wrong? Do I need to enable CSGO anywhere in the developer portal to use the CSGO API?
url = f'https://public-api.tracker.gg/v2/csgo/standard/profile/steam/{player_id}'
headers = {'Authorization': f'TRN-Api-Key: {TRACKER_GG}'}
print(url)
print(headers)
response = requests.get(url, headers=headers)
print(response)
if response.ok:
data = response.json()
username = data['data']['platformInfo']['platformUserHandle']
level = data['data']['segments'][0]['stats']['level']['displayValue']
kd_ratio = data['data']['segments'][0]['stats']['kdRatio']['displayValue']
message = f"{username} has a level of {level} and a K/D ratio of {kd_ratio}."
await ctx.send(message)
else:
await ctx.send("Failed to retrieve CS:GO stats.")