Looking for getting OAuth token in Python

Looking for assistance as I think I am pretty close but keep getting 401 error. Any help would be appreciated. clientID and clientSecret have been removed for privacy. I want to start using the API to import data in JSON and start playing around the data.

#Setting up the parameters to use
baseURL = “https://api.twitch.tv/helix/
clientID = [Redacted]
clientSecret = [Redacted]
headers = {‘client-id’: clientID, ‘Authorization’: clientSecret}
indent = 2

import requests

#r = requests.get(‘https://api.twitch.tv/helix/search/channels?query=a_seagull’, headers=headers, params=payload)
r = requests.get(‘https://api.twitch.tv/helix/search/channels?query=a_seagull’, headers=headers)

headers = {‘client-id’: clientID, ‘Authorization’: clientSecret}
OAuth = requests.get(‘https://id.twitch.tv/oauth2/validate’.client_id = clientID, client_secret = clientSecret, scopes=[twitch.constants.OAUTH_SCOPE_ANALYTICS_READ_EXTENSIONS])

Why you requesting The Analytics Extensions then calling the search endpoint?

What are you actaully trying to do, as this will advise us what kind of token you need?

Hi Barry, I would like to try and hit some of the endpoints listed in reference here (e.g. Videos, Streams, etc.): https://dev.twitch.tv/docs/api/reference. Sorry for the confusion.

Then you probably want to generate, store, use and reuse a App Access/Client Credentials token

Documented here:


Here is a pythong example I wrote that will generate and use such a token

It doesn’t give advise on store/recall/reuse of a token

1 Like

Awesome! Thank you very much, Barry.

1 Like

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