Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Sep 18, 2024
1 parent 8e21809 commit 60f859e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ static function getInfo($row)
$msg[] = "<a href='{$link}' target='_blank'>{$link}</a>";
}
break;
case SocialMediaPublisher::SOCIAL_TYPE_LINKEDIN["name"]:
if (!empty($row['json']->response->publishResult) && !empty($row['json']->response->publishResult->xRestLiId)) {
$link = "https://www.linkedin.com/feed/update/" . $row['json']->response->publishResult->xRestLiId;
$msg[] = "<a href='{$link}' target='_blank'>{$link}</a>";
}
break;
}
$row['msg'] = implode('<br>', $msg);
}
Expand Down
40 changes: 34 additions & 6 deletions plugin/SocialMediaPublisher/Objects/SocialUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,16 @@ static function finalizeLinkedInUploadSession($accessToken, $videoURN, $uploadTo

// Check if HTTP status code is 200
if ($httpCode === 200) {
return ['error' => false, 'response' => $responseArray];
return [
'error' => false,
'httpCode' => $httpCode,
'response' => $responseArray
];
} else {
_error_log("Finalize upload session failed with HTTP code: $httpCode");
return [
'error' => true,
'httpCode' => $httpCode,
'message' => 'HTTP error code: ' . $httpCode,
'response' => $responseArray
];
Expand Down Expand Up @@ -687,6 +692,7 @@ static function publishVideo($accessToken, $authorUrn, $videoUrn, $title, $descr

$ch = curl_init($url);

// Collect headers and response
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer {$accessToken}",
"Content-Type: application/json",
Expand All @@ -696,11 +702,18 @@ static function publishVideo($accessToken, $authorUrn, $videoUrn, $title, $descr
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); // Get headers and response body

$response = curl_exec($ch);

// Log the raw response
_error_log("Publish Video Raw Response:\n" . $response);
// Separate headers and body
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size); // Extract headers
$body = substr($response, $header_size); // Extract response body

// Log headers and body separately
_error_log("Publish Video Headers:\n" . $headers);
_error_log("Publish Video Body:\n" . $body);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Get HTTP response code
_error_log("Publish Video HTTP Code: $httpCode");
Expand All @@ -714,21 +727,36 @@ static function publishVideo($accessToken, $authorUrn, $videoUrn, $title, $descr

curl_close($ch);

// Parse the response
$responseArray = json_decode($response, true);
// Parse the headers to find x-restli-id
$xRestLiId = null;
if (preg_match('/x-restli-id: (.*)\r/', $headers, $matches)) {
$xRestLiId = trim($matches[1]); // Get x-restli-id from headers
}

// Log the x-restli-id
_error_log("x-restli-id: " . $xRestLiId);

// Parse the response body
$responseArray = json_decode($body, true);

// Log the parsed response
_error_log("Publish Video Parsed Response:\n" . print_r($responseArray, true));

// Check if HTTP status code is 201 (Created)
if ($httpCode === 201) {
return ['error' => false,'httpCode' => $httpCode, 'response' => $responseArray];
return [
'error' => false,
'httpCode' => $httpCode,
'xRestLiId' => $xRestLiId,
'response' => $responseArray
];
} else {
_error_log("Publish video failed with HTTP code: $httpCode");
return [
'error' => true,
'message' => 'HTTP error code: ' . $httpCode,
'httpCode' => $httpCode,
'xRestLiId' => $xRestLiId,
'response' => $responseArray
];
}
Expand Down

0 comments on commit 60f859e

Please sign in to comment.