Invalid OAuth token error trying to get Streams API

I’m getting an unauthorized error trying to get the data from the streams api:

{'error': 'Unauthorized', 'status': 401, 'message': 'Invalid OAuth token'}

I’ve tried passing both my App Access Token and the Users OAuth token with no success. I’m using the following python code to call the api:

twitch_api_url = 'https://api.twitch.tv/helix/'

def twitch(endpoint, token, **kwargs):

    headers = {

        'Authorization': 'Bearer %s' % token,

        'Client-Id': settings.TWITCH_CLIENT_ID

    }

    url = twitch_api_url + endpoint

    response = requests.get(url, headers=headers, params=kwargs)

    return response.text

Whenever i logout it should be getting rid of the old tokens stored in localstorage so the tokens that i’m using should be new and not expired. I’m not sure what i am missing?

Then your token expired, or you are not passing what you think you are passing to the headers. (Possibley that the token is blank/missing when calling the function)

You can use Authentication | Twitch Developers to validate a token.

Should being the operative word but might not be the case.

Also really shouldn’t be storing an “app access token” in localstorage since that doesn’t belong to the user using your site.

You were right thanks for the hint.

Ok