Update MediaService.php
This commit is contained in:
@@ -61,11 +61,11 @@ class MediaService {
|
|||||||
$mediaUrl = $decoded['url'] ?? ($decoded['data'][0]['url'] ?? null);
|
$mediaUrl = $decoded['url'] ?? ($decoded['data'][0]['url'] ?? null);
|
||||||
if (!$mediaUrl) throw new Exception('No media url from Graph');
|
if (!$mediaUrl) throw new Exception('No media url from Graph');
|
||||||
|
|
||||||
// Descargar contenido: primero wget (más confiable con Facebook CDN), luego curl como fallback
|
// Descargar contenido usando cascade robusto (curl, file_get_contents, shell/proc/wget)
|
||||||
$content = $this->downloadWithWget($mediaUrl, !empty($this->token) ? ['Authorization: Bearer ' . $this->token] : []);
|
$content = $this->downloadUrl($mediaUrl);
|
||||||
if ($content === false) {
|
if ($content === false) {
|
||||||
// Obtener URL fresca del Graph API (la anterior puede haber expirado tras el intento fallido)
|
// 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);
|
$resp2 = $this->graphApiRequest($endpoint);
|
||||||
if ($resp2) {
|
if ($resp2) {
|
||||||
$decoded2 = json_decode($resp2, true);
|
$decoded2 = json_decode($resp2, true);
|
||||||
@@ -73,7 +73,6 @@ class MediaService {
|
|||||||
} else {
|
} else {
|
||||||
$freshUrl = $mediaUrl;
|
$freshUrl = $mediaUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->downloadUrl($freshUrl);
|
$content = $this->downloadUrl($freshUrl);
|
||||||
}
|
}
|
||||||
if ($content === false) throw new Exception('Failed to download media content from ' . $mediaUrl);
|
if ($content === false) throw new Exception('Failed to download media content from ' . $mediaUrl);
|
||||||
|
|||||||
Reference in New Issue
Block a user