Skip to content

Instantly share code, notes, and snippets.

@BtbN
Created August 19, 2017 10:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BtbN/97ce4f3105d9d471a18c36475178ba35 to your computer and use it in GitHub Desktop.
Save BtbN/97ce4f3105d9d471a18c36475178ba35 to your computer and use it in GitHub Desktop.
GetTwitchFollowers for Google App Script
function GetTwitchFollowers(channelName) {
var twitchApiOptions = {
'headers': {
'Accept': 'application/vnd.twitchtv.v5+json',
'Client-ID': 'ayb2n4px2z8t5iinjyvf1snlnw1sdw'
}
};
var idx = channelName.lastIndexOf('/');
if(idx !== -1)
channelName = channelName.substring(idx + 1);
var res = UrlFetchApp.fetch('https://api.twitch.tv/kraken/users?login=' + channelName, twitchApiOptions);
var jObj = JSON.parse(res);
var channelId = jObj.users[0]._id;
res = UrlFetchApp.fetch('https://api.twitch.tv/kraken/channels/' + channelId, twitchApiOptions);
jObj = JSON.parse(res);
return jObj.followers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment