Soru ESP32 ile Spotify API kullanımı

Bu konuyu okuyanlar

brhnnn

Öğrenci
Katılım
17 Nisan 2023
Mesajlar
1
Reaksiyon puanı
0
Puanları
1
Yaş
18
İyi günler, ben başlıkta da belirttiğim gibi ESP32 (ttgo t-call) ile Spotify'dan ne dinlediğimi seri porta yazdırmak istiyorum.

C:
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>

const char* ssid = "";
const char* password = "";

const char* host = "api.spotify.com";
const int httpsPort = 443;

const char* accessToken = "";


void setup() {
  Serial.begin(115200);
  delay(1000);
 
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    WiFiClientSecure client;
    client.setInsecure();
    
    if (client.connect(host, httpsPort)) {
      String endpoint = "/v1/me/player/recently-played?limit=1";
      String header = "GET " + endpoint + " HTTP/1.1\r\n" +
                      "Host: " + host + "\r\n" +
                      "Authorization: Bearer " + accessToken + "\r\n" +
                      "Connection: close\r\n\r\n";
      client.print(header);
      
      while (client.connected()) {
        String line = client.readStringUntil('\n');
        if (line == "\r") {
          break;
        }
      }

      String response = client.readString();
      Serial.println(response);

    } else {
      Serial.println("Connection failed");
    }
  }
  delay(60000); // 1 dakika bekleme
}
}

Bu kodu yazdım fakat şarkı bilgisini Access token ile çektiğim için her saat yeni bir token girmem gerekiyor. Bu sorunu nasıl çözebilirim? Mümkünse örnek bir kod verebilir misiniz?
 
Üst