So after a good amount of research, I found out that nobody had created (or at least documented) a good way to get YouTube Subscribers in a Nightbot command. So as any good coder/programmer/engineer does, I created a way. And honestly I’m pretty proud of it.
Here are the steps to create this command.
First of all there is no YouTube nightbot API it seems that covers getting this information. But it just so happens that you can create a Google API Key, and then from there use the Google API to get a small JSON document that has this number.
The link to this instructions for this is right here:
Once you do that, then you have to create the URL, I found this URL and changed it to my liking:
Replace the Channel ID and the API key as follows (both are given in the instructions above).
Once you first go to this link in your browser, it will tell you that you need to follow a link to enable Google API Data… Something or another (it was quite a few hours ago that I did this).
Once you go to the link and enable it, refresh the page and then you should get some good old JSON.
Okay so now we need to parse that information so that we just get the subscriber number.
What I found the best way to do this, is to use $(urlfetch json) to parse the code. Now that you have that, you want to put that in a variable and then use it somehow. Here is my final command:
!addcom !youtube $(eval subs = JSON.parse( ‘$(urlfetch https://www.googleapis.com/youtube/v3/channels?part=statistics&id=CHANNELID&key=APIKEY )’ ); 'I have a Youtube channel! Currently we have ’ + subs.items.statistics.subscriberCount + ’ subscribers! Check it out at: https://www.youtube.com/user/channel ')
And voila! You now have a way to inject the amount of subscribers into your nightbot commands! Thank you for reading
Edited: Changed the Link to use Channel ID and to use $(urlfetch JSON) (Channel ID is going to be more reliable as that works better with youtube).
Thank you to u/SecretOil for the JSON and RokettoJanpu on NightDev Community for your input!