Created
August 19, 2017 10:55
-
-
Save BtbN/97ce4f3105d9d471a18c36475178ba35 to your computer and use it in GitHub Desktop.
GetTwitchFollowers for Google App Script
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
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