YouTube Subscriber Count Display


#21

@mlseim
The video tutorial for the subscriber count display.
I liked the idea of this project, and wanted to build one.


#22

You need to first get an API key from Google Developer:
https://console.developers.google.com/

I will try to come up with an example script.
The one shown from 2014 is no longer valid.
Google/Youtube now requires API key/authentication

They have an optional ‘referrer’, which would be your website domain name. But if using the imp agent, I’m not sure yet what that would be. It can be omitted, but that might allow others to use your API key.

I’ll see what I can do with it during the next couple days.

The API request will look something like this:
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=channel_id&key=your_key


#23

Do you have your own website online?

I used a PHP script to get the data.

It is easier to make it work with a PHP script first. That allows you to test it out and make sure it works.

Let’s get to that part first.

Here is a link to instructions on getting the required keys and codes for making it work. It’s a big PNG image, so I’ll just put the link, not the whole image …

Let me know if you get that far.


#24

I’m getting real close.
I can get the JSON directly using the Agent, so no PHP will be needed.
Awaiting some assistance on parsing the large JSON array.

You can in the meantime work on how a value will be displayed on an LED display. That might be something from Adafruit that uses UART? For now, we will just display the count on the server log (for proof of concept).

In my mind, the agent will get the subscriber count every 30 minutes. That would be 48 per day which is way below the quota limit.

You will still need to set-up your api, using these instructions:


#25

@GobiDoo

Below is the IMP code.
You need to use your own channel key and api key.

This is how you obtain those keys:

`// AGENT CODE for Google YouTube API

function request_stats(temp) {
// ==================================================
// Enter your channel and key here
local channel="UCwKu7TSU3HnpAfA";
local key="H6yt4fKifmJLp92x0hGR1dBKi8T6Rmn80FaHRBeHM";
// ==================================================
local request=http.get("https://www.googleapis.com/youtube/v3/channels?part=statistics&id="+channel+"&key="+key,{ "Accept" : "application/json" } )
local responseTable=request.sendsync();
if (responseTable.statuscode == 200) 
{
// Decode the JSON
local data=http.jsondecode(responseTable.body)
local subscriberCountToDisplay = data.items[0].statistics.subscriberCount;
local viewCountToDisplay = data.items[0].statistics.viewCount;
local videoCountToDisplay = data.items[0].statistics.videoCount;
// Send count to device
device.send( "SubscriberCount", subscriberCountToDisplay );
//server.log(subscriberCountToDisplay);
} else 
{
server.log("Error response: " + responseTable.statuscode);
}
}
device.on("impMsg", request_stats);`
`// DEVICE CODE for Google YouTube API

// This function will handle displaying value on LED Display
function led_display(value){
//
server.log("LED DIsplay: " + value); 
//
// LED Display
//
}
// 30 Second Clock
function clockTick() {
imp.wakeup(30, clockTick);
local temp=1; // in case you want to send a value to the agent for some reason
// Request the Subscriber Count every 30 seconds ...
agent.send("impMsg",temp);
}

clockTick();
agent.on("SubscriberCount", led_display);`

I learned a lot with this project.
Hope it helps you get started with your LED project.