Hallo zusammen,
ich bin komplett neu was Arduino angeht und wollte wissen, ob es möglich ist über den API Key von TikTok die Follower Anzahl auf einer Dot Matrix anzuzeigen. Ich habe es mit dem Youtube Account geschafft (dank einer Vorlage) aber mir fehlt das Know How wie ich hier auf die TikTok Daten zugreifen könnte.
Kann mir jemand helfen?
/*******************************************************************
The code for this project is based on code originally written by Pawel A. Hernik
https://youtu.be/mn9L85bhyjI
Revised by Lewis for DIY Machines
https://youtu.be/QWaVYCVoqbc
combined with the code written by Brian Lough
YouTube: https://www.youtube.com/brianlough
Tindie: https://www.tindie.com/stores/brianlough/
Twitter: https://twitter.com/witnessmenow
supplemented by code by doit4you
YouTube: https://www.youtube.com/channel/UCi8Ir6oKE0PlzMgqWZA0SmQ
Read YouTube Channel statistics from the YouTube API
and print them to the serial monitor
Compatible Boards:
* Any ESP8266 board
* Any ESP32 board
Recommended Board: D1 Mini ESP8266
*******************************************************************/
/*
WEMOS D1 mini board to LED matrix module
VCC - 3V3
GND - G
DIN - D8
CS - D7
CLK - D6
Important: Only connect after the sketch has been uploaded to the Arduino board, otherwise there is an error while uploading:
D0 - RST
*/
// ----------------------------
// Standard Libraries
// ----------------------------
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif
#include <WiFiClient.h>
#include "Arduino.h" //LED
#define NUM_MAX 4 //LED
#define ROTATE 90 //LED
#define DIN_PIN 15 // D8 //LED
#define CS_PIN 13 // D7 //LED
#define CLK_PIN 12 // D6 //LED
#include "max7219.h" //LED
#include "fonts.h" //LED
// ----------------------------
// Additional Libraries - each of these will need to be installed
// ----------------------------
// Library for connecting to the YouTube API
// https://github.com/witnessmenow/arduino-youtube-api
// (search for "youtube" in the Arduino Library Manager)
#include <YoutubeApi.h>
// Library used for parsing Json from the API responses
// https://github.com/bblanchon/ArduinoJson
// (search for "Arduino Json" in the Arduino Library Manager)
#include <ArduinoJson.h>
const char ssid[] = "Blah"; // your network SSID (name)
const char password[] = "Blah"; // your network key
#define API_KEY "Blah" // your Google API key
#define CHANNEL_ID "Blah" // part of the channel url
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);
unsigned long timeBetweenRequests = 15 * 1000; // 15 seconds, in milliseconds
void setup() {
Serial.begin(115200);
initMAX7219(); //LED
sendCmdAll(CMD_SHUTDOWN,1); //LED
sendCmdAll(CMD_INTENSITY,0); //LED
// Set WiFi to 'station' mode and disconnect
// from the AP if it was previously connected
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("------------------------");
//convert long int to char*
char subscriberCount[50]; //LED
sprintf(subscriberCount, "%ld", api.channelStats.subscriberCount); //LED
char viewCount[50]; //LED
sprintf(viewCount, "%ld", api.channelStats.viewCount); //LED
printStringWithShift("",40); //LED
printStringWithShift(subscriberCount,40); //LED
printStringWithShift("",40); //LED
}
delay(timeBetweenRequests);
// deep sleep: To save power, put the entire board into deep sleep for a defined period of time.
// During this period of time the LEDs do not light up.
//
Serial.println("I'll go right away for 600 seconds into deep sleep."); //deep sleep
ESP.deepSleep(600e6); //deep sleep
}
// from here everything for LED display
//
int showChar(char ch, const uint8_t *data)
{
int len = pgm_read_byte(data);
int i,w = pgm_read_byte(data + 1 + ch * len);
for (i = 0; i < w; i++)
scr[NUM_MAX*8 + i] = pgm_read_byte(data + 1 + ch * len + 1 + i);
scr[NUM_MAX*8 + i] = 0;
return w;
}
// =======================================================================
int dualChar = 0;
unsigned char convertPolish(unsigned char _c)
{
unsigned char c = _c;
if(c==196 || c==197 || c==195) {
dualChar = c;
return 0;
}
if(dualChar) {
switch(_c) {
case 133: c = 1+'~'; break; // 'ą'
case 135: c = 2+'~'; break; // 'ć'
case 153: c = 3+'~'; break; // 'ę'
case 130: c = 4+'~'; break; // 'ł'
case 132: c = dualChar==197 ? 5+'~' : 10+'~'; break; // 'ń' and 'Ą'
case 179: c = 6+'~'; break; // 'ó'
case 155: c = 7+'~'; break; // 'ś'
case 186: c = 8+'~'; break; // 'ź'
case 188: c = 9+'~'; break; // 'ż'
//case 132: c = 10+'~'; break; // 'Ą'
case 134: c = 11+'~'; break; // 'Ć'
case 152: c = 12+'~'; break; // 'Ę'
case 129: c = 13+'~'; break; // 'Ł'
case 131: c = 14+'~'; break; // 'Ń'
case 147: c = 15+'~'; break; // 'Ó'
case 154: c = 16+'~'; break; // 'Ś'
case 185: c = 17+'~'; break; // 'Ź'
case 187: c = 18+'~'; break; // 'Ż'
default: break;
}
dualChar = 0;
return c;
}
switch(_c) {
case 185: c = 1+'~'; break;
case 230: c = 2+'~'; break;
case 234: c = 3+'~'; break;
case 179: c = 4+'~'; break;
case 241: c = 5+'~'; break;
case 243: c = 6+'~'; break;
case 156: c = 7+'~'; break;
case 159: c = 8+'~'; break;
case 191: c = 9+'~'; break;
case 165: c = 10+'~'; break;
case 198: c = 11+'~'; break;
case 202: c = 12+'~'; break;
case 163: c = 13+'~'; break;
case 209: c = 14+'~'; break;
case 211: c = 15+'~'; break;
case 140: c = 16+'~'; break;
case 143: c = 17+'~'; break;
case 175: c = 18+'~'; break;
default: break;
}
return c;
}
// =======================================================================
void printCharWithShift(unsigned char c, int shiftDelay) {
c = convertPolish(c);
if (c < ' ' || c > MAX_CHAR) return;
c -= 32;
int w = showChar(c, font);
for (int i=0; i<w+1; i++) {
delay(shiftDelay);
scrollLeft();
refreshAll();
}
}
// =======================================================================
void printStringWithShift(const char* s, int shiftDelay){
while (*s) {
printCharWithShift(*s++, shiftDelay);
}
}
// =======================================================================
unsigned int convToInt(const char *txt)
{
unsigned int val = 0;
for(int i=0; i<strlen(txt); i++)
if(isdigit(txt[i])) val=val*10+(txt[i]&0xf);
return val;
}