Created
March 8, 2017 20:47
-
-
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.
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 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