1
1
/* ******************************************************************
2
- * Read YouTube Channel statistics from the YouTube API using an
3
- * ESP32
4
- *
5
- * By Brian Lough
6
- * https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
2
+ Read YouTube Channel statistics from the YouTube API on
3
+ an ESP32 and print them to the serial monitor
4
+
5
+ Parts:
6
+ Any ESP32 board
7
+
8
+ If you find what I do useful and would like to support me,
9
+ please consider becoming a sponsor on Github
10
+ https://github.com/sponsors/witnessmenow/
11
+
12
+ Written by Brian Lough
13
+ YouTube: https://www.youtube.com/brianlough
14
+ Tindie: https://www.tindie.com/stores/brianlough/
15
+ Twitter: https://twitter.com/witnessmenow
7
16
*******************************************************************/
8
17
9
- #include < YoutubeApi.h>
18
+ // ----------------------------
19
+ // Standard Libraries
20
+ // ----------------------------
21
+
10
22
#include < WiFi.h>
11
23
#include < WiFiClientSecure.h>
12
24
13
- #include < ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
25
+ // ----------------------------
26
+ // Additional Libraries - each one of these will need to be installed.
27
+ // ----------------------------
28
+
29
+ #include < YoutubeApi.h>
30
+ // Library for connecting to the Youtube API
31
+
32
+ // Search for "youtube" in the Arduino Library Manager
33
+ // https://github.com/witnessmenow/arduino-youtube-api
34
+
35
+ #include < ArduinoJson.h>
36
+ // Library used for parsing Json from the API responses
37
+
38
+ // Search for "Arduino Json" in the Arduino Library manager
39
+ // https://github.com/bblanchon/ArduinoJson
14
40
15
41
// ------- Replace the following! ------
16
- char ssid[] = " ssid " ; // your network SSID (name)
17
- char password[] = " password " ; // your network key
18
- #define API_KEY " ENTER_YOUR_API_KEY " // your google apps API Token
42
+ char ssid[] = " xxx " ; // your network SSID (name)
43
+ char password[] = " yyyy " ; // your network key
44
+ #define API_KEY " zzzz " // your google apps API Token
19
45
#define CHANNEL_ID " UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel
20
-
46
+ // ------- ---------------------- ------
21
47
22
48
WiFiClientSecure client;
23
49
YoutubeApi api (API_KEY, client);
24
50
25
- unsigned long api_mtbs = 60000 ; // mean time between api requests
26
- unsigned long api_lasttime; // last time api request has been done
51
+ unsigned long timeBetweenRequests = 60000 ;
52
+ unsigned long nextRunTime;
27
53
28
54
long subs = 0 ;
29
55
@@ -55,7 +81,7 @@ void setup() {
55
81
56
82
void loop () {
57
83
58
- if (millis () - api_lasttime > api_mtbs ) {
84
+ if (millis () > nextRunTime ) {
59
85
if (api.getChannelStatistics (CHANNEL_ID))
60
86
{
61
87
Serial.println (" ---------Stats---------" );
@@ -73,6 +99,6 @@ void loop() {
73
99
Serial.println (" ------------------------" );
74
100
75
101
}
76
- api_lasttime = millis ();
102
+ nextRunTime = millis () + timeBetweenRequests ;
77
103
}
78
104
}
0 commit comments