Skip to content

witnessmenow/arduino-youtube-api

Repository files navigation

Arduino YouTube API Library

arduino-library-badge Build Status

A wrapper for the YouTube API for Arduino. Works on both ESP8266 and ESP32.

Imgur

Support what I do!

I have created a lot of different Arduino libraries that I hope people can make use of. If you enjoy my work, please consider becoming a GitHub sponsor!

Getting a Google Apps API key (Required!)

https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UCezJOfu7OtqGzd5xrP3q6WA&key=PutYourNewlyGeneratedKeyHere

If everything is working correctly you should see the JSON channel statistics for my YouTube channel!

Installing

The easiest way to install this library is through the Arduino Library Manager, just search for "Youtube". Alternately, you can also download the latest version and import it into the IDE with the "Add .ZIP Library" feature.

This library depends on the ArduinoJson library by Benoît Blanchon for parsing messages from the API. If you are using Arduino 1.8.10 or newer the library manager will install this automatically alongside YoutubeApi. If you are using an older version of Arduino you will have to download it yourself: search for "ArduinoJson" in the Arduino Library Manager or download the latest release from here.

Basic Use

Include YoutubeApi in your project:

#include <YoutubeApi.h>

and pass it an API key and an SSL client:

#define API_KEY "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
WiFiClientSecure client; //For ESP8266 and ESP32 boards
YoutubeApi api(API_KEY, client);

then once you're connected to WiFi you can start requesting data from the API:

#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA"

if(api.getChannelStatistics(CHANNEL_ID)) {
    Serial.print("Subscriber Count: ");
    Serial.println(api.channelStats.subscriberCount);
}

If you don't know it, you can find your own YouTube channel ID here. See the examples for more details on how to use the library.

Supported Data Methods

Currently the only implemented method is getting channel statistics, but the library can be easily extended. Please raise an issue if there is a method you are looking for.

License

This library is licensed under the terms of the MIT License.