# Getting Top Games in Python

**URL:** <https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256>\
**Category:** API\
**Created:** [September 21, 2020, 7:45pm UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256 "2020-09-21T19:45:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![massm90s](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@massm90s](https://discuss.dev.twitch.com/u/massm90s)\
**Post date:** [September 21, 2020, 7:45pm UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/1 "2020-09-21T19:45:41Z")

</div>

Hi all,

I’m trying to get the top games sorted by users ([Reference | Twitch Developers](https://dev.twitch.tv/docs/api/reference#get-top-games))  
in Python, but it’s not working for me.

Here’s my code

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

I’m getting this result:  
 ![image](https://d2opxh93rbxzdn.cloudfront.net/original/2X/b/b4b1c7fec025d04da2a300cecc4403b7fe1d4b2c.png)  
Even though the Reference indicates no token/authentication is needed.

Thanks in advance for your help.

M

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 21, 2020, 7:46pm UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/2 "2020-09-21T19:46:21Z")

</div>

All of helix requires a token.

The docs were bugged and had the requirement accidentally removed

As per the example:

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

```

---

<div class="post-metadata">

**Author:** ![massm90s](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@massm90s](https://discuss.dev.twitch.com/u/massm90s)\
**Post date:** [September 21, 2020, 7:47pm UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/3 "2020-09-21T19:47:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 21, 2020, 7:50pm UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/4 "2020-09-21T19:50:14Z")

</div>

Added a uservoice for the issue

> **[It is unclear that "Authentication none" means "any token"](https://twitch.uservoice.com/forums/310213-developers/suggestions/41447842-it-is-unclear-that-authentication-none-means-an)**
>
> Some endpoint in the docs say "authentication none" leading to some confusion
> 
> 
> https://discuss.dev.twitch.tv/t/getting-top-games-in-python/28256/

> [@massm90s](#):
>
> Any way to get those kind of stats without token?

A token is required

> [@massm90s](#):
>
> Or how can I get the Authorization code?

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

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

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

---

<div class="post-metadata">

**Author:** ![massm90s](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@massm90s](https://discuss.dev.twitch.com/u/massm90s)\
**Post date:** [September 21, 2020, 7:51pm UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/5 "2020-09-21T19:51:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![massm90s](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@massm90s](https://discuss.dev.twitch.com/u/massm90s)\
**Post date:** [September 22, 2020, 8:51am UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/6 "2020-09-22T08:51:08Z")

</div>

> [@BarryCarlyon](#):
>
> ```auto
> curl -X GET 'https://api.twitch.tv/helix/games/top' \
> -H 'Authorization: Bearer cfabdegwdoklmawdzdo98xt2fo512y' \
> -H 'Client-Id: uo6dggojyb8d6soh92zknwmi5ej1q2'
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 22, 2020, 11:18am UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/7 "2020-09-22T11:18:54Z")

</div>

> [@massm90s](#):
>
> Is it possible to get stats about top games for my website without authorization? The authorization is not working for me for some reason.

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

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

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

> <https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/app_access_tokens>
>
> //github.com/BarryCarlyon/twitch\_misc/tree/main/authentication/app\_access\_tokens

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

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [October 22, 2020, 11:18am UTC](https://discuss.dev.twitch.com/t/getting-top-games-in-python/28256/8 "2020-10-22T11:18:55Z")

</div>

Closed on October 22, 2020, 11:18am UTC

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