Update MediaService.php

This commit is contained in:
Lizandro Guarnizo
2026-02-21 09:43:28 -05:00
parent 1c2bc3eac3
commit f05d4a20cb
+3 -4
View File
@@ -61,11 +61,11 @@ class MediaService {
$mediaUrl = $decoded['url'] ?? ($decoded['data'][0]['url'] ?? null);
if (!$mediaUrl) throw new Exception('No media url from Graph');
// Descargar contenido: primero wget (más confiable con Facebook CDN), luego curl como fallback
$content = $this->downloadWithWget($mediaUrl, !empty($this->token) ? ['Authorization: Bearer ' . $this->token] : []);
// Descargar contenido usando cascade robusto (curl, file_get_contents, shell/proc/wget)
$content = $this->downloadUrl($mediaUrl);
if ($content === false) {
// Obtener URL fresca del Graph API (la anterior puede haber expirado tras el intento fallido)
error_log("[MediaService] wget download failed, getting fresh URL...");
error_log("[MediaService] downloadUrl failed, getting fresh URL...");
$resp2 = $this->graphApiRequest($endpoint);
if ($resp2) {
$decoded2 = json_decode($resp2, true);
@@ -73,7 +73,6 @@ class MediaService {
} else {
$freshUrl = $mediaUrl;
}
$content = $this->downloadUrl($freshUrl);
}
if ($content === false) throw new Exception('Failed to download media content from ' . $mediaUrl);