Skip to content

Instantly share code, notes, and snippets.

@mchambers
Created March 8, 2017 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchambers/ed0c08a45815e5b99903e67845451d30 to your computer and use it in GitHub Desktop.
Save mchambers/ed0c08a45815e5b99903e67845451d30 to your computer and use it in GitHub Desktop.
App Script for retrieving the concurrent viewer count of a YouTube live stream by channel ID.
function doGet(e) {
var channelId=e.parameter["channelId"];
var results=YouTube.Search.list("snippet", {"channelId":channelId, "type":"video", "eventType":"live"})
if(results.items.length!=0) {
var broadcastResults=YouTube.Videos.list("liveStreamingDetails", {"id":results.items.pop().id.videoId});
var output={"concurrentViewers":broadcastResults.items.pop().liveStreamingDetails.concurrentViewers};
return ContentService.createTextOutput(JSON.stringify(output)).setMimeType(ContentService.MimeType.JSON);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment