fix: code review issues — Instagram arg count, LinkedIn file handle, TikTok data_get, YouTube token timestamp
This commit is contained in:
parent
6c2a354594
commit
aa6bc88335
5 changed files with 22 additions and 18 deletions
|
|
@ -233,7 +233,7 @@ private function publishCarousel(string $instagramId, string $accessToken, ?stri
|
|||
Log::error('Instagram carousel container creation failed', [
|
||||
'body' => $carouselResponse->body(),
|
||||
]);
|
||||
$this->handleApiError($carouselResponse, 'Instagram API error');
|
||||
$this->handleApiError($carouselResponse);
|
||||
}
|
||||
|
||||
$carouselId = $carouselResponse->json()['id'] ?? null;
|
||||
|
|
|
|||
|
|
@ -367,17 +367,16 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn):
|
|||
|
||||
// Step 2: Upload chunks
|
||||
$uploadedPartIds = [];
|
||||
$handle = fopen($tempFile, 'r');
|
||||
|
||||
foreach ($uploadInstructions as $index => $instruction) {
|
||||
$uploadUrl = $instruction['uploadUrl'];
|
||||
$firstByte = $instruction['firstByte'];
|
||||
$lastByte = $instruction['lastByte'];
|
||||
$uploadUrl = data_get($instruction, 'uploadUrl');
|
||||
$firstByte = data_get($instruction, 'firstByte');
|
||||
$lastByte = data_get($instruction, 'lastByte');
|
||||
|
||||
$chunkLength = $lastByte - $firstByte + 1;
|
||||
$handle = fopen($tempFile, 'r');
|
||||
fseek($handle, $firstByte);
|
||||
$chunkData = fread($handle, $chunkLength);
|
||||
fclose($handle);
|
||||
|
||||
Log::info('LinkedIn Page uploading video chunk', [
|
||||
'index' => $index,
|
||||
|
|
@ -410,6 +409,8 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn):
|
|||
Log::info('LinkedIn Page video chunk uploaded', ['index' => $index, 'etag' => $etag]);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
// Step 3: Finalize upload
|
||||
Log::info('LinkedIn Page finalizing video upload', ['videoUrn' => $videoUrn]);
|
||||
|
||||
|
|
|
|||
|
|
@ -348,17 +348,16 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn):
|
|||
|
||||
// Step 2: Upload chunks
|
||||
$uploadedPartIds = [];
|
||||
$handle = fopen($tempFile, 'r');
|
||||
|
||||
foreach ($uploadInstructions as $index => $instruction) {
|
||||
$uploadUrl = $instruction['uploadUrl'];
|
||||
$firstByte = $instruction['firstByte'];
|
||||
$lastByte = $instruction['lastByte'];
|
||||
$uploadUrl = data_get($instruction, 'uploadUrl');
|
||||
$firstByte = data_get($instruction, 'firstByte');
|
||||
$lastByte = data_get($instruction, 'lastByte');
|
||||
|
||||
$chunkLength = $lastByte - $firstByte + 1;
|
||||
$handle = fopen($tempFile, 'r');
|
||||
fseek($handle, $firstByte);
|
||||
$chunkData = fread($handle, $chunkLength);
|
||||
fclose($handle);
|
||||
|
||||
Log::info('LinkedIn uploading video chunk', [
|
||||
'index' => $index,
|
||||
|
|
@ -391,6 +390,8 @@ private function doUploadVideo(string $tempFile, $mediaItem, string $ownerUrn):
|
|||
Log::info('LinkedIn video chunk uploaded', ['index' => $index, 'etag' => $etag]);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
// Step 3: Finalize upload
|
||||
Log::info('LinkedIn finalizing video upload', ['videoUrn' => $videoUrn]);
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ private function publishVideo(PostPlatform $postPlatform, $media): array
|
|||
|
||||
Log::info('TikTok video init response', ['data' => $data]);
|
||||
|
||||
$publishId = data_get($data, 'data')['publish_id'] ?? null;
|
||||
$publishId = data_get($data, 'data.publish_id');
|
||||
|
||||
if (! $publishId) {
|
||||
throw new \Exception('TikTok did not return a publish_id');
|
||||
|
|
@ -191,7 +191,7 @@ private function publishPhotos(PostPlatform $postPlatform, $mediaCollection): ar
|
|||
|
||||
Log::info('TikTok photo init response', ['data' => $data]);
|
||||
|
||||
$publishId = data_get($data, 'data')['publish_id'] ?? null;
|
||||
$publishId = data_get($data, 'data.publish_id');
|
||||
|
||||
if (! $publishId) {
|
||||
throw new \Exception('TikTok did not return a publish_id');
|
||||
|
|
@ -226,7 +226,7 @@ private function waitForPublishStatus(string $publishId, int $maxAttempts = 20):
|
|||
}
|
||||
|
||||
$data = $response->json();
|
||||
$status = data_get($data, 'data')['status'] ?? 'UNKNOWN';
|
||||
$status = data_get($data, 'data.status', 'UNKNOWN');
|
||||
|
||||
Log::info('TikTok publish status', [
|
||||
'status' => $status,
|
||||
|
|
|
|||
|
|
@ -51,12 +51,14 @@ private function createGoogleClient(SocialAccount $account): GoogleClient
|
|||
$client->setClientId(config('services.google.client_id'));
|
||||
$client->setClientSecret(config('services.google.client_secret'));
|
||||
|
||||
$remainingSeconds = $account->token_expires_at
|
||||
? max(0, (int) now()->diffInSeconds($account->token_expires_at, false))
|
||||
: 3600;
|
||||
|
||||
$tokenData = [
|
||||
'access_token' => $account->access_token,
|
||||
'created' => $account->token_expires_at
|
||||
? $account->token_expires_at->subHour()->getTimestamp()
|
||||
: time(),
|
||||
'expires_in' => 3600,
|
||||
'created' => time(),
|
||||
'expires_in' => $remainingSeconds,
|
||||
];
|
||||
|
||||
if ($account->refresh_token) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue