Use Oauth Token in API

Hello There !

I’m trying to do an extension with Helix but i have some trouble. I have generated my Oauth Token but i don’t know how to use it.

I use a function to retrieve the information of a streamer by its ID but the server responded with a status of 401.

async function getUserInfos() {
    return await new Promise(resolve => {
        $.ajax({
            dataType: 'json',
            headers: {'Client-ID': config.client_id,
                      'Authorization': config.user_acces_token},
            url: "https://api.twitch.tv/helix/channels?broadcaster_id=42797849",
            success: user =>
                user && user.data && user.data[0]
                    ? resolve(user.data[0])
                    : resolve(null)
        })
    });
}

Can you help me with my Token ?
Thank you !

You need to use the correct prefix for the token. As shown in the example https://dev.twitch.tv/docs/api/reference#get-channel-information the authorization header should be Authorization: Bearer YouTokenHere. If you don’t include Bearer before your token, it wont work.

1 Like

Thanks for your fast reply !

It seems to be better but i have a new error “Uncaught SyntaxError: Unexpected identifier”

And i don’t understand why and how resolve this.

            headers: {'Client-ID': config.client_id,
                      'Authorization': config.user_acces_token},

should be

            headers: {'Client-ID': config.client_id,
                      'Authorization': 'Bearer ' + config.user_acces_token},
1 Like

Thank a lot !
I’ve been stuck on it for a long time.

I hope I didn’t bother you. Thank you again !

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