|
@@ -8,6 +8,7 @@ use Facebook\Exceptions\FacebookSDKException;
|
|
use Facebook\Facebook;
|
|
use Facebook\Facebook;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class InstagramService implements SmmPlatformInterface
|
|
class InstagramService implements SmmPlatformInterface
|
|
@@ -115,8 +116,10 @@ class InstagramService implements SmmPlatformInterface
|
|
|
|
|
|
// If single image
|
|
// If single image
|
|
if (count($imagePaths) === 1) {
|
|
if (count($imagePaths) === 1) {
|
|
|
|
+ Log::info('单图发帖');
|
|
$imagePath = $imagePaths[0];
|
|
$imagePath = $imagePaths[0];
|
|
// Create media container for single image
|
|
// Create media container for single image
|
|
|
|
+ Log::info('开始创建媒体容器');
|
|
$postData = [
|
|
$postData = [
|
|
'image_url' => $imagePath, // Assuming images are publicly accessible
|
|
'image_url' => $imagePath, // Assuming images are publicly accessible
|
|
'caption' => $message,
|
|
'caption' => $message,
|
|
@@ -131,6 +134,7 @@ class InstagramService implements SmmPlatformInterface
|
|
return ['status' => false, 'data' => '错误:无法创建媒体容器 - ' . json_encode($containerData)];
|
|
return ['status' => false, 'data' => '错误:无法创建媒体容器 - ' . json_encode($containerData)];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Log::info('开始发布媒体容器');
|
|
// Publish the container
|
|
// Publish the container
|
|
$publishResponse = Http::post("https://graph.instagram.com/v21.0/{$igUserId}/media_publish", [
|
|
$publishResponse = Http::post("https://graph.instagram.com/v21.0/{$igUserId}/media_publish", [
|
|
'creation_id' => $containerData['id'],
|
|
'creation_id' => $containerData['id'],
|
|
@@ -153,6 +157,7 @@ class InstagramService implements SmmPlatformInterface
|
|
$requestContent = [];
|
|
$requestContent = [];
|
|
$responseContent = [];
|
|
$responseContent = [];
|
|
foreach ($imagePaths as $imagePath) {
|
|
foreach ($imagePaths as $imagePath) {
|
|
|
|
+ Log::info('多图发帖');
|
|
$postData = [
|
|
$postData = [
|
|
'image_url' => asset($imagePath),
|
|
'image_url' => asset($imagePath),
|
|
'is_carousel_item' => true,
|
|
'is_carousel_item' => true,
|
|
@@ -162,6 +167,7 @@ class InstagramService implements SmmPlatformInterface
|
|
'url'=>"https://graph.instagram.com/v21.0/{$igUserId}/media",
|
|
'url'=>"https://graph.instagram.com/v21.0/{$igUserId}/media",
|
|
'postData' => $postData,
|
|
'postData' => $postData,
|
|
];
|
|
];
|
|
|
|
+ Log::info('上传子媒体容器');
|
|
$childResponse = Http::asForm()->post("https://graph.instagram.com/v21.0/{$igUserId}/media", $postData);
|
|
$childResponse = Http::asForm()->post("https://graph.instagram.com/v21.0/{$igUserId}/media", $postData);
|
|
|
|
|
|
$childData = $childResponse->json();
|
|
$childData = $childResponse->json();
|
|
@@ -182,6 +188,7 @@ class InstagramService implements SmmPlatformInterface
|
|
'url'=>"https://graph.instagram.com/v21.0/{$igUserId}/media",
|
|
'url'=>"https://graph.instagram.com/v21.0/{$igUserId}/media",
|
|
'postData' => $postData,
|
|
'postData' => $postData,
|
|
];
|
|
];
|
|
|
|
+ Log::info('Create carousel container');
|
|
$carouselResponse = Http::asForm()->post("https://graph.instagram.com/v21.0/{$igUserId}/media",$postData );
|
|
$carouselResponse = Http::asForm()->post("https://graph.instagram.com/v21.0/{$igUserId}/media",$postData );
|
|
|
|
|
|
$carouselData = $carouselResponse->json();
|
|
$carouselData = $carouselResponse->json();
|
|
@@ -197,6 +204,7 @@ class InstagramService implements SmmPlatformInterface
|
|
'url'=>"https://graph.instagram.com/v21.0/{$igUserId}/media_publish",
|
|
'url'=>"https://graph.instagram.com/v21.0/{$igUserId}/media_publish",
|
|
'postData' => $postData,
|
|
'postData' => $postData,
|
|
];
|
|
];
|
|
|
|
+ Log::info('Publish carousel');
|
|
$publishResponse = Http::post("https://graph.instagram.com/v21.0/{$igUserId}/media_publish", $postData);
|
|
$publishResponse = Http::post("https://graph.instagram.com/v21.0/{$igUserId}/media_publish", $postData);
|
|
|
|
|
|
$publishData = $publishResponse->json();
|
|
$publishData = $publishResponse->json();
|
|
@@ -223,6 +231,7 @@ class InstagramService implements SmmPlatformInterface
|
|
if (empty($videoPath)) {
|
|
if (empty($videoPath)) {
|
|
return ['status' => false, 'data' => '错误:未提供视频路径'];
|
|
return ['status' => false, 'data' => '错误:未提供视频路径'];
|
|
}
|
|
}
|
|
|
|
+ Log::info("开始上传视频");
|
|
$igUserId = $this->configData['accountInfo']['account_id'];
|
|
$igUserId = $this->configData['accountInfo']['account_id'];
|
|
|
|
|
|
// Create media container for video
|
|
// Create media container for video
|
|
@@ -237,6 +246,7 @@ class InstagramService implements SmmPlatformInterface
|
|
if (!isset($containerData['id'])) {
|
|
if (!isset($containerData['id'])) {
|
|
return ['status' => false, 'data' => '错误:无法创建视频容器 - ' . json_encode($containerData)];
|
|
return ['status' => false, 'data' => '错误:无法创建视频容器 - ' . json_encode($containerData)];
|
|
}
|
|
}
|
|
|
|
+ Log::info("创建视频的媒体容器完成");
|
|
// Check container status (video processing may take time)
|
|
// Check container status (video processing may take time)
|
|
$status = 'IN_PROGRESS';
|
|
$status = 'IN_PROGRESS';
|
|
$maxAttempts = 10;
|
|
$maxAttempts = 10;
|
|
@@ -257,6 +267,7 @@ class InstagramService implements SmmPlatformInterface
|
|
return ['status' => false, 'data' => '错误:视频处理失败'];
|
|
return ['status' => false, 'data' => '错误:视频处理失败'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ Log::info("检查容器状态完成");
|
|
if ($status !== 'FINISHED') {
|
|
if ($status !== 'FINISHED') {
|
|
return ['status' => false, 'data' => '错误:视频处理超时'];
|
|
return ['status' => false, 'data' => '错误:视频处理超时'];
|
|
}
|
|
}
|
|
@@ -266,7 +277,7 @@ class InstagramService implements SmmPlatformInterface
|
|
'access_token' => $accessToken,
|
|
'access_token' => $accessToken,
|
|
];
|
|
];
|
|
$publishResponse = Http::post("https://graph.instagram.com/v21.0/{$igUserId}/media_publish",$postData);
|
|
$publishResponse = Http::post("https://graph.instagram.com/v21.0/{$igUserId}/media_publish",$postData);
|
|
-
|
|
|
|
|
|
+ Log::info("发布视频完成");
|
|
$publishData = $publishResponse->json();
|
|
$publishData = $publishResponse->json();
|
|
if (!isset($publishData['id'])) {
|
|
if (!isset($publishData['id'])) {
|
|
return ['status' => false, 'data' => '错误:无法发布视频 - ' . json_encode($publishData)];
|
|
return ['status' => false, 'data' => '错误:无法发布视频 - ' . json_encode($publishData)];
|