How to get subscriber in channel?

Hello experts,

I looking for how to get subscriber list in channel.

I use that ‘https://api.twitch.tv/kraken/users//subscriptions/’.

But, I met error below.
{“error”:“Unauthorized”,“status”:401,“message”:“authentication failed”}

What is needed parameter? or Do it have problem of access step?

Do you have sample source about this?

The docs for the endpoint show an example request and response: https://dev.twitch.tv/docs/v5/reference/users/#check-user-subscription-by-channel

The reason you’re getting a 401 response is because you need to send an Authorization: OAuth ... header with a User Access token for that channel which has the user_subscriptions scope.

Thank you for your answer!

I met error this time.
{“error”:“Bad Request”,“status”:400,“message”:“No client id specified”}

I tested below code.

var url=‘https://api.twitch.tv/kraken/channel’;
request({
url: url,
method: ‘GET’,
headers: [
{
‘Authorization’: 'OAuth ’ + req.user.refreshToken.access_token,
‘Accept’: ‘application/vnd.twitchtv.v5+json’,
‘Client_ID’: config.twitchtv.clientID
}
],
},
function (error, response, body) {
if (error) throw error;
console.log(body);
}
);

Your headers is wrong:

You put an object in an array, should be just an object

headers:
{
‘Authorization’: 'OAuth ’ + req.user.refreshToken.access_token,
‘Accept’: ‘application/vnd.twitchtv.v5+json’,
‘Client_ID’: config.twitchtv.clientID
}
,

Thank you for your quick answer.

I understanded your answer like below.

var url=‘https://api.twitch.tv/kraken/channel’;

        var headersArray = [
            ['Authorization', 'OAuth ' + req.user.accessToken],
            ['Accept', 'application/vnd.twitchtv.v5+json'],
            ['Client_Id', config.twitchtv.clientID],                
        ];
        request({ 
            url: url, 
            method: 'GET', 
            headers: headersArray 
            }, 
            function (error, response, body) { 
            if (error) throw error; 
            console.log(body); 
            } 
        ); 

============================================

Is it correct?
The test result is below.

{“status”:400,“message”:“Invalid authorization code”}

I used accessToken that received token when twitch’s authentication.

Is my method correct ? or Which use token?

Why is there so much random bold and weird formatting in your posts.

The code should be:

    var url=‘https://api.twitch.tv/kraken/channel’;

    request({ 
        url: url, 
        method: 'GET', 
        headers: {
            'Authorization': 'OAuth ' + req.user.accessToken,
            'Accept': 'application/vnd.twitchtv.v5+json'
        }
    },  function (error, response, body) { 
        if (error) throw error; 
            console.log(body); 
    } ); 

As you are providing an oAuth, you don’t need to specific a clientID so I have ommitted this header

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