Getting Top Games in Python

Hi all,

I’m trying to get the top games sorted by users (Reference | Twitch Developers)
in Python, but it’s not working for me.

Here’s my code

import requests
URL=“https://api.twitch.tv/helix/games/top
response=requests.get(URL)
print(response.text)

I’m getting this result:
image
Even though the Reference indicates no token/authentication is needed.

Thanks in advance for your help.

M

All of helix requires a token.

The docs were bugged and had the requirement accidentally removed

As per the example:

curl -X GET 'https://api.twitch.tv/helix/games/top' \
-H 'Authorization: Bearer cfabdegwdoklmawdzdo98xt2fo512y' \
-H 'Client-Id: uo6dggojyb8d6soh92zknwmi5ej1q2'

Thanks a lot Barry!
Any way to get those kind of stats without token?
Or how can I get the Authorization code?

Added a uservoice for the issue

A token is required

You probably want a “OAuth client credentials flow” token which is for server to server requests and can be generated without user interaction

Excellent, appreciate it!
I’ll give it a try.

Hi again, Barry.
My question might be a bit beginner. But let me explain what I’m trying to do.
Is it possible to get stats about top games for my website without authorization? The authorization is not working for me for some reason.
All I need is just a code in Python to receive JSON output of top games.
I really appreciate your responses.

Best,
M

No authorisation is required

The example is an example token which won’t work because it’s the example.

Your website (server side) will need to generate an App Access Token

Then call the API with the generated token and the Client ID.

Make sure you are not using your “Client Secret” as a token, as it’s not a token it’s a Client Secret.

I have not written a python example but these examples may help

To get an app access token it’s just a single HTTP Post to Twitch with your ClientID and secret

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.