pororia
December 11, 2018, 9:41am
1
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?
Dist
December 11, 2018, 12:18pm
2
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.
pororia
December 12, 2018, 2:10pm
3
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
}
,
pororia
December 12, 2018, 3:51pm
5
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
system
Closed
January 11, 2019, 11:13pm
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.