Augux
Augux

Reputation: 55

How can i check if a twitch channel exists?

Im trying to write a code that checks for twitch channels if they exist or not, i tried using request but the statusCode its allways 200

request(`https://www.twitch.tv/${args[1]}`, function(error, response, body){
    console.log('statusCode', response.statusCode)

edit: tried using twith api kraken but doesn't seem to work, if i use existing channels its the same response.

request('https://api.twitch.tv/kraken/channels/' + args[1], function(channel, response) {
    console.log(channel)
    if (channel == null) {
      return console.log("doesnt exists")
    } else {
      return console.log("Exists")
    }

Upvotes: 0

Views: 802

Answers (1)

jackik
jackik

Reputation: 93

The status code of an HTML request is the status code of the request, not what was requested. 200 means that the request went through fine without problems.

You could either look through the response and body of the request or try the Kraken, which I'm not very familiar with. Have you looked through the docs?

The docs about this part use this syntax:

curl -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
-X GET 'https://api.twitch.tv/kraken/channels/44322889'

Your syntax probably works fine. The issue is probably that the response isn't null, but rather something like an empty object.

What response ARE you getting? What is your console output if you use console.log(channel); console.log(response);

I hope I could help a bit.

Upvotes: 1

Related Questions