Twitch Helix API: HTTP Error 401 - invalid access token

I am using Helix API and creating an app in Python and Flask. But I encountered a problem. Everytime I make a request it just returns 401 - invalid access token.

User authorizes app from this link: “https://id.twitch.tv/oauth2/authorize?client_id=rzmgq7ybviufdw3llgx1upt3w9ila5&response_type=code&redirect_uri=http://localhost:5000&scope=openid”, it redirects to the “http://localhost:5000/?code=<access_token>&scope=openid” and validates token using a GET request. But everytime it just returns “invalid access token” error.

Source code:

from flask import Flask, request
from requests import get
app = Flask(__name__)


@app.route('/')
def validatetoken():
    ACCESS_TOKEN = request.args.get('code')
    r = get(url='https://id.twitch.tv/oauth2/validate', headers={'Authorization': f'Bearer {ACCESS_TOKEN}'})
    return r.json()

Thanks in advance!

After getting the code you need to exchange the code for an access token

The code is NOT an access token.

Step 3

NodeJS example that may help

Ok. Now it works, one more thing does the /oauth2/token require an redirect_uri? Without specyfing it, it wouldn’t let me in.

As documented, yes

OK. Thank you very much!

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