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