A wrapper for the YouTube API for Arduino. Works on both ESP8266 and ESP32.
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!
- Go to the Google developer dashboard and create a new project
- In the "API & Services" menu, go to "Credentials" and create a new API key.
- Head to the Google API library, find the "YouTube Data API v3", and "Enable" it for your project.
- Make sure the following URL works for you in your browser (change the key at the end!):
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!
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.
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.
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.
This library is licensed under the terms of the MIT License.