User auth flow invalid oauth token

I’m working on linking twitch user email to my custom app with user auth flow. Currently i am able to get a token from Twitch API however when i send the oauth token to get the users email i get this response.

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

I’m getting a new token after every request for authorization and I’m trying to use it with the following python code to request the email.

@api_view(['GET'])

def save_twitch_user_token(request):

    params = {

        'code': request.query_params['code'],

        'scope': request.query_params['scope']

    }

    endpoint = "https://api.twitch.tv/helix/users"

    headers = {

        'Authorization': 'Bearer %s' % params['code'],

        'Client-Id': settings['TWITCH_CLIENT_ID']

    }

    response = requests.request(method='GET', url=endpoint, headers=headers)

    url = settings['FRONTEND_CALLBACK_URI']

    return HttpResponse(response.text, status=status.HTTP_200_OK)

This is as far as i’ve gotten. I’m wondering if me getting all these different tokens are messing me up somehow? any help is appreaciated. Thanks.

The code in the querystring is not an OAuth token. Your server needs to complete the Authorization Code flow by exchanging that code for an Access Token and Refresh Token.

Step 3 of the Auth Code Flow docs show what you need to do. Getting Tokens: OAuth | Twitch Developers

ahh thank you so much. I will continue on trying to follow the next steps.

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