Gibt es eine Möglichkeit, die genaue Abonnentenzahl eines YouTube-Kanals zu ermitteln?
Posted: 03 Jan 2025, 13:46
Ich erstelle einen Zähler für einen YouTube-Kanal, aber das Problem mit meinem Code und der API besteht darin, dass der Kanal auf YouTube 1.32.000 Abonnenten anzeigt und mein Zähler mir 1.320 Abonnenten anzeigt, die tatsächliche Zahl jedoch lautet 1326, also habe ich überlegt, ob es einen besseren Weg gibt, das zu machen?
Code: Select all
import time
import requests
#from Adafruit_SSD1306 import SSD1306_128_64
# API key and channel details
API_KEY = 'this part works im just not giving it'
CHANNEL_ID = 'this part works im just not giving it'
API_URL = f'https://www.googleapis.com/youtube/v3/channels?part=statistics&id={CHANNEL_ID}&key={API_KEY}'
def fetch_subscriber_count():
"""Fetch subscriber count from YouTube API."""
try:
response = requests.get(API_URL)
response.raise_for_status()
data = response.json()
subscriber_count = data['items'][0]['statistics']['subscriberCount']
return int(subscriber_count)
except Exception as e:
print(f"Error fetching subscriber count: {e}")
return None
def display_subscriber_count(count):
"""Display subscriber count on the OLED without image generation."""
if count is not None:
print(f"Subscribers: {count}")
else:
print("Error fetching data")
# Main loop
try:
while True:
subscriber_count = fetch_subscriber_count()
display_subscriber_count(subscriber_count)
time.sleep(60) # Update every minute
except KeyboardInterrupt:
print("Exiting...")