Last active
February 1, 2018 16:35
-
-
Save micalevisk/d4a84a9fc8b157c9b4f375f59014da3f to your computer and use it in GitHub Desktop.
simple JS script which use Twitch.tv API v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env node | |
// USE: ./getInfoTwitchTv.js <channelname> | |
'use strict'; | |
if(process.argv.length < 2) return; | |
var channel = process.argv[2].trim(); | |
if(!channel) return; | |
var request = require('request'); | |
const URL = 'https://api.twitch.tv/kraken/streams/' + channel; | |
var options = { | |
url: URL, | |
qs: { client_id: '<CLIENT ID>' } | |
}; | |
function callback(error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var infoStream = JSON.parse(body).stream; | |
if(infoStream == null) return; | |
var infoChannel = infoStream.channel; | |
var info = { | |
"title": infoChannel.status , | |
"game": infoStream.game , | |
"viewers": infoStream.viewers , | |
"followers": infoChannel.followers , | |
"user": infoChannel.name , | |
"partner": infoChannel.partner | |
}; | |
console.log( JSON.stringify(info, null, ' ') ); | |
} | |
} | |
request(options, callback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "info_twitchtv", | |
"version": "1.0.0", | |
"description": "Show channel informations from Twitch Tv", | |
"main": "getInfoTwitchTv.js", | |
"author": "Micael Levi", | |
"license": "ISC", | |
"dependencies":{ | |
"request": "latest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output example
on bash with cURL and jq