OAuth for code to get analytics

I’m trying to get some data of certain games but to do that I need a code from oauth2/authorize. Unless there is a way i can bypass this or there is something else that I haven’t seen yet, I’m quiet lost as the redirect_uri doesn’t work.

# main.py
# Get Code from oauth2/authorize
def get_code():
    url = 'https://id.twitch.tv/oauth2/authorize'
    params = {
        'client_id': CLIENT_ID,
        'redirect_uri': 'http://localhost:5000',
        'response_type': 'code',
        'scope': 'analytics:read:games'
    response = requests.get(url, params=params)

# webserver.py
class MainHandler(tornado.web.RequestHandler):
    async def get(self):
       # print stuff
    async def post(self):
       # print stuff
if __name__ == "__main__":
    app = tornado.web.Application([
        ('', MainHandler),

You also need to own the game you are trying to collect analytics for, (ie your user account is a member of an organistation that owns the game you wish to collect analytics of)

oAuth works as follows

Step 1) user clicks a link to visit twitch
Step 2) user accepts or delcines access
Step 3) user returns to your redirect URI with a ?code
Step 4) Exchange the code for a token.

Your code above appears to be trying to fetch Step 1 instead of redirecting the user to Twitch

Is there any way I can collect data of certain games?

Only if you own the game on Twitch as part of an organisation.

The game stats endpoint is intended for use by the game developer or publisher, not random people

hmm alright thanks. Then is there a way I can collect data on clips? Through the api

The clips API is documented here

1 Like

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