Upload file test-api-key.php via GUI

This commit is contained in:
2026-03-29 22:28:35 +02:00
parent 2a70e23c6b
commit 32fb4c8204

View File

@@ -0,0 +1,98 @@
<?php
/**
* Test-Skript für YouTube API Key
* Führe aus: php test-api-key.php
*/
define('WP_USE_THEMES', false);
require('../../../wp-load.php');
echo "=== YouTube API Key Test ===\n\n";
// Hole API Key aus Customizer
$api_key = get_theme_mod('youtube_api_key', '');
$api_key_from_config = defined('YOUTUBE_API_KEY') ? YOUTUBE_API_KEY : '';
echo "API Key aus Customizer: " . ($api_key ? substr($api_key, 0, 10) . '...' : 'NICHT GESETZT') . "\n";
echo "API Key aus wp-config: " . ($api_key_from_config ? substr($api_key_from_config, 0, 10) . '...' : 'NICHT GESETZT') . "\n\n";
$active_key = $api_key ? $api_key : $api_key_from_config;
if (empty($active_key)) {
echo "⚠️ Kein API Key gefunden!\n\n";
echo "So fügst du einen API Key hinzu:\n";
echo "1. Gehe zu: Design → Customizer → Video & Livestream\n";
echo "2. Trage dort deinen YouTube API Key ein\n";
echo "3. Klicke auf 'Veröffentlichen'\n\n";
echo "Oder füge in wp-config.php hinzu:\n";
echo "define('YOUTUBE_API_KEY', 'DEIN_KEY_HIER');\n";
exit;
}
echo "✓ API Key gefunden: " . substr($active_key, 0, 15) . "...\n\n";
// Test: Video-Status abfragen
$test_video_id = 'ithwtp7aJlM'; // NashvilleBirdCam Stream
echo "Teste API Key mit Video ID: $test_video_id\n\n";
$url = sprintf(
'https://www.googleapis.com/youtube/v3/videos?id=%s&part=snippet,liveStreamingDetails&key=%s',
rawurlencode($test_video_id),
rawurlencode($active_key)
);
echo "API Request: " . substr($url, 0, 100) . "...\n\n";
$response = wp_remote_get($url, array('timeout' => 10));
if (is_wp_error($response)) {
echo "❌ Fehler beim API Request: " . $response->get_error_message() . "\n";
exit;
}
$status_code = wp_remote_retrieve_response_code($response);
echo "HTTP Status: $status_code\n\n";
if ($status_code !== 200) {
echo "❌ API Fehler (Status $status_code)\n";
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if (isset($data['error']['message'])) {
echo "Fehlermeldung: " . $data['error']['message'] . "\n";
if (strpos($data['error']['message'], 'API key not valid') !== false) {
echo "\n⚠️ Der API Key ist ungültig!\n";
echo "Bitte überprüfe den Key im Customizer oder erstelle einen neuen.\n";
}
}
exit;
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if (empty($data['items'])) {
echo "❌ Video nicht gefunden oder nicht verfügbar\n";
exit;
}
echo "✅ API Key funktioniert!\n\n";
$video = $data['items'][0];
$title = $video['snippet']['title'] ?? 'Unbekannt';
$state = $video['snippet']['liveBroadcastContent'] ?? 'none';
echo "Video Titel: $title\n";
echo "Live Status: $state\n";
if ($state === 'live') {
echo "🔴 Das Video ist LIVE!\n";
} elseif ($state === 'upcoming') {
echo "⏰ Das Video ist geplant (noch nicht live)\n";
} else {
echo "⚫ Das Video ist NICHT live (aufgezeichnet oder offline)\n";
}
echo "\n=== Test erfolgreich ===\n";