-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e295021
commit 1610fb6
Showing
4 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************* | ||
* Read YouTube Channel statistics from the YouTube API using an | ||
* ESP32 | ||
* | ||
* By Brian Lough | ||
* https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA | ||
*******************************************************************/ | ||
|
||
#include <YoutubeApi.h> | ||
#include <WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
|
||
#include <ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed. | ||
|
||
//------- Replace the following! ------ | ||
char ssid[] = "ssid"; // your network SSID (name) | ||
char password[] = "password"; // your network key | ||
#define API_KEY "ENTER_YOUR_API_KEY" // your google apps API Token | ||
#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel | ||
|
||
|
||
WiFiClientSecure client; | ||
YoutubeApi api(API_KEY, client); | ||
|
||
unsigned long api_mtbs = 60000; //mean time between api requests | ||
unsigned long api_lasttime; //last time api request has been done | ||
|
||
long subs = 0; | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
|
||
// Attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
|
||
/* Explicitly set the ESP32 to be a WiFi-client, otherwise, it by default, | ||
would try to act as both a client and an access-point and could cause | ||
network-issues with your other WiFi-devices on your WiFi-network. */ | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.println("IP address: "); | ||
IPAddress ip = WiFi.localIP(); | ||
Serial.println(ip); | ||
|
||
|
||
} | ||
|
||
void loop() { | ||
|
||
if (millis() - api_lasttime > api_mtbs) { | ||
if(api.getChannelStatistics(CHANNEL_ID)) | ||
{ | ||
Serial.println("---------Stats---------"); | ||
Serial.print("Subscriber Count: "); | ||
Serial.println(api.channelStats.subscriberCount); | ||
Serial.print("View Count: "); | ||
Serial.println(api.channelStats.viewCount); | ||
Serial.print("Comment Count: "); | ||
Serial.println(api.channelStats.commentCount); | ||
Serial.print("Video Count: "); | ||
Serial.println(api.channelStats.videoCount); | ||
// Probably not needed :) | ||
//Serial.print("hiddenSubscriberCount: "); | ||
//Serial.println(api.channelStats.hiddenSubscriberCount); | ||
Serial.println("------------------------"); | ||
|
||
} | ||
api_lasttime = millis(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=YoutubeApi | ||
version=1.0.0 | ||
version=1.1.0 | ||
author=Brian Lough | ||
maintainer=Brian Lough <[email protected]> | ||
sentence=A wrapper for the YouTube API for Arduino (supports ESP8266 & WiFi101 boards) | ||
|
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
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