Skip to content

Commit c62dff8

Browse files
authored
Merge pull request #23 from witnessmenow/V2
V2
2 parents 1610fb6 + 89bec62 commit c62dff8

File tree

9 files changed

+239
-508
lines changed

9 files changed

+239
-508
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@
3030
.piolibdeps
3131
.clang_complete
3232
.gcc-flags.json
33+
.pio/
34+
.vscode/

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ Currently the only implemented method is getting the channel statistics but it c
55

66
![Imgur](http://i.imgur.com/FmXyW4E.png)
77

8+
### Support what I do!
9+
10+
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!](https://github.com/sponsors/witnessmenow/)
11+
812
## Getting a Google Apps API key (Required!)
913

1014
* Create an application [here](https://console.developers.google.com)
1115
* On the API Manager section, go to "Credentials" and create a new API key
1216
* Enable your application to communicate the YouTube Api [here](https://console.developers.google.com/apis/api/youtube)
1317
* Make sure the following URL works for you in your browser (Change the key at the end!):
14-
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UCu7_D0o48KbfhpEohoP7YSQ&key=PutYourNewlyGeneratedKeyHere
18+
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UCezJOfu7OtqGzd5xrP3q6WA&key=PutYourNewlyGeneratedKeyHere
1519

1620
## Installing
1721

18-
The downloaded code can be included as a new library into the IDE selecting the menu:
19-
20-
Sketch / include Library / Add .Zip library
22+
The easiest way to install this library is through the aduino library manager, just search for "Youtube"
2123

2224
You also have to install the ArduinoJson library written by [Benoît Blanchon](https://github.com/bblanchon). Search for it on the Arduino Library manager or get it from [here](https://github.com/bblanchon/ArduinoJson).
2325

examples/ESP32/ChannelStatistics/ChannelStatistics.ino

+41-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,55 @@
11
/*******************************************************************
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
716
*******************************************************************/
817

9-
#include <YoutubeApi.h>
18+
// ----------------------------
19+
// Standard Libraries
20+
// ----------------------------
21+
1022
#include <WiFi.h>
1123
#include <WiFiClientSecure.h>
1224

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
1440

1541
//------- 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
1945
#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel
20-
46+
//------- ---------------------- ------
2147

2248
WiFiClientSecure client;
2349
YoutubeApi api(API_KEY, client);
2450

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;
2753

2854
long subs = 0;
2955

@@ -55,7 +81,7 @@ void setup() {
5581

5682
void loop() {
5783

58-
if (millis() - api_lasttime > api_mtbs) {
84+
if (millis() > nextRunTime) {
5985
if(api.getChannelStatistics(CHANNEL_ID))
6086
{
6187
Serial.println("---------Stats---------");
@@ -73,6 +99,6 @@ void loop() {
7399
Serial.println("------------------------");
74100

75101
}
76-
api_lasttime = millis();
102+
nextRunTime = millis() + timeBetweenRequests;
77103
}
78104
}

examples/ESP8266/ChannelStatistics/ChannelStatistics.ino

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
11
/*******************************************************************
2-
* Read YouTube Channel statistics from the YouTube API *
3-
* *
4-
* By Brian Lough *
5-
* https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA *
2+
Read YouTube Channel statistics from the YouTube API on
3+
an ESP8266 and print them to the serial monitor
4+
5+
Parts:
6+
D1 Mini ESP8266 (or any ESP8266) * - http://s.click.aliexpress.com/e/uzFUnIe
7+
* = Affilate
8+
9+
If you find what I do useful and would like to support me,
10+
please consider becoming a sponsor on Github
11+
https://github.com/sponsors/witnessmenow/
12+
13+
Written by Brian Lough
14+
YouTube: https://www.youtube.com/brianlough
15+
Tindie: https://www.tindie.com/stores/brianlough/
16+
Twitter: https://twitter.com/witnessmenow
617
*******************************************************************/
718

8-
#include <YoutubeApi.h>
19+
// ----------------------------
20+
// Standard Libraries
21+
// ----------------------------
22+
923
#include <ESP8266WiFi.h>
1024
#include <WiFiClientSecure.h>
1125

12-
#include <ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
26+
// ----------------------------
27+
// Additional Libraries - each one of these will need to be installed.
28+
// ----------------------------
29+
30+
#include <YoutubeApi.h>
31+
// Library for connecting to the Youtube API
32+
33+
// Search for "youtube" in the Arduino Library Manager
34+
// https://github.com/witnessmenow/arduino-youtube-api
35+
36+
#include <ArduinoJson.h>
37+
// Library used for parsing Json from the API responses
38+
39+
// Search for "Arduino Json" in the Arduino Library manager
40+
// https://github.com/bblanchon/ArduinoJson
1341

1442
//------- Replace the following! ------
1543
char ssid[] = "xxx"; // your network SSID (name)
1644
char password[] = "yyyy"; // your network key
1745
#define API_KEY "zzzz" // your google apps API Token
1846
#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel
19-
47+
//------- ---------------------- ------
2048

2149
WiFiClientSecure client;
2250
YoutubeApi api(API_KEY, client);
2351

24-
unsigned long api_mtbs = 60000; //mean time between api requests
25-
unsigned long api_lasttime; //last time api request has been done
52+
unsigned long timeBetweenRequests = 60000;
53+
unsigned long nextRunTime;
2654

2755
long subs = 0;
2856

@@ -50,12 +78,16 @@ void setup() {
5078
IPAddress ip = WiFi.localIP();
5179
Serial.println(ip);
5280

81+
// Required if you are using ESP8266 V2.5 or above
82+
client.setInsecure();
5383

84+
// If you want to enable some extra debugging
85+
api._debug = true;
5486
}
5587

5688
void loop() {
5789

58-
if (millis() - api_lasttime > api_mtbs) {
90+
if (millis() > nextRunTime) {
5991
if(api.getChannelStatistics(CHANNEL_ID))
6092
{
6193
Serial.println("---------Stats---------");
@@ -73,6 +105,6 @@ void loop() {
73105
Serial.println("------------------------");
74106

75107
}
76-
api_lasttime = millis();
108+
nextRunTime = millis() + timeBetweenRequests;
77109
}
78110
}

examples/ESP8266/ChannelStatisticsWithWifiManager/ChannelStatisticsWithWifiManager.ino

-174
This file was deleted.

0 commit comments

Comments
 (0)