List of subscribers returns 401

Hi everyone,

I’m trying to get the list of subscribers in my channel but it returns a 401 in the console.

Here’s what I have done:

I log in in my application and pass this scope:

Twitch.login({
     scope: ['channel_subscriptions']
});

Then once I am logged in I do this:

`

  $.ajax({
    type: 'GET',
    url: 'https://api.twitch.tv/kraken/channels/MY_CHANNEL_HERE/subscriptions',
    headers: {
        'Client-ID': 'XXXXXXXXXXXXX'
    },
    success: function(data) {
        console.log(data);
    }
});

}`

The above is all wrapped in:

Twitch.init({clientId: CLIENT_ID}, function(error, status) {}

The console.log(data); at the AJAX request returns me 401 unfortunately.

Any thoughts?

Thanks.

You’re not sending your OAuth token with the request.

If you look at the example in the docs https://dev.twitch.tv/docs/v5/reference/channels#get-channel-subscribers you’ll see that you need to use the Authorization header along with the appropriate OAuth token.

Thanks Dist,

Do I pass the token as a parameter at my ajax request or at the URL?

Cheers

Since you seem to be using the JS SDK, you may want to use Twitch.api() for the API calls instead, which will include the oauth automatically for you. Alternatively, you should be able to find it in Window.sessionStorage.

1 Like

Thanks 3ventic,

I can get indeed get the Token via the sessionStorage.

I was just wondering how do I pass it at my ajax request afterwards ?

Thanks

Authorization: OAuth [tokenhere] header, so 'Authorization': 'OAuth ' + token in the headers object.

1 Like

Aren’t you amazing? Cheers for that mate! Works !

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