ESP Pobieranie statystyk z Youtube
1. Pobierz i dodaj odpowiednie biblioteki, link github do bibliotek: https://github.com/espressif/arduino-esp32
2. Na początek należy stworzyć projekt w konsoli dewelopera: https://console.cloud.google.com/cloud-resource-manager?pli=1
Włącz API YouTube Data API v3 (Enable)
Dodaj Credentials (Create Credentials -> API Key)
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif
#include <WiFiClientSecure.h>
#include <YoutubeApi.h>
#include <ArduinoJson.h>
#define API_KEY "xxx..." // your google apps API key for Youtube Data API access
#define CHANNEL_ID "xxx..." // your Youtube channel ID
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);
const char* ssid ="xxx..."; //wifi ssid
const char* password = "xxx..."; //wifi password
unsigned long timeBetweenRequests = 60 * 1000; // 60 seconds, in milliseconds
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Connect to the WiFi network
Serial.print("\nConnecting to WiFi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("\nWiFi connected!");
Serial.print("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
#ifdef ESP8266
// Required if you are using ESP8266 V2.5 or above
client.setInsecure();
#endif
}
void loop() {
if(api.getChannelStatistics(CHANNEL_ID)) {
Serial.println("\n---------Stats---------");
Serial.print("Subscriber Count: ");
Serial.println(api.channelStats.subscriberCount);
Serial.print("View Count: ");
Serial.println(api.channelStats.viewCount);
Serial.print("Video Count: ");
Serial.println(api.channelStats.videoCount);
Serial.println("------------------------");
}
delay(timeBetweenRequests);
}
Zobacz: Połączenie ESP8266 z WiFi