Hello, I am having issues with my python application and making requests on behalf of the user. I have visited here
{
"identified": true,
"token": {
"valid": true,
"authorization": {
"scopes": [
"channel_commercial",
"channel_editor",
"channel_subscriptions",
"user_read"
],
"created_at": "2017-01-17T06:01:21Z",
"updated_at": "2017-01-17T06:01:21Z"
},
"user_name": "chinnbot",
"client_id": "CLIENT ID"
},
"_links": {
"channel": "https:\/\/api.twitch.tv\/kraken\/channel",
"chat": "https:\/\/api.twitch.tv\/kraken\/chat\/chinnbot",
"teams": "https:\/\/api.twitch.tv\/kraken\/teams",
"user": "https:\/\/api.twitch.tv\/kraken\/user",
"users": "https:\/\/api.twitch.tv\/kraken\/users\/chinnbot",
"streams": "https:\/\/api.twitch.tv\/kraken\/streams\/chinnbot",
"ingests": "https:\/\/api.twitch.tv\/kraken\/ingests",
"channels": "https:\/\/api.twitch.tv\/kraken\/channels\/chinnbot"
}
}
This response leads me to believe that the OAuth token is valid. Now when I try make a request on behalf of the user on my website I’m getting this response:
{u'status': 401, u'message': u'Token invalid or missing required scope', u'error': u'Unauthorized'}
The strange thing is this works when I’m testing with my main account on Twitch, but when I switch to an alternative test account this 401 response appears.
I am sending the Client ID as you can see in this pre_request:
def change_twitch_header(uri, headers, body):
auth = headers.get('Authorization')
if auth:
auth = auth.replace('Bearer', 'OAuth')
headers['Authorization'] = auth
if app.debug:
headers['Client-ID'] = cfg.config.twitch.dev_client_id
else:
headers['Client-ID'] = cfg.config.twitch.client_id
return uri, headers, body
Here is a Gist to most of my code. This line is where I make a request on behalf of the user just to get their channel object for their identity.
Here is a link of my IDE’s debugger when my IDE hits Line 66. You can see that the me response object is returning the 401 response described above and that the twitch.authorized_response() is making the propper post and getting the access_token, refresh_token, and scope back as it should be according to the Twitch-API/Authentication Step 4
So I’m at a loss, why does it work for my main account but when I try any other account it fails. What am I doing wrong? How can I fix it?
Thank you in advance for your time.