Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkedIn Share API 'ugcPosts' response 504 gateway timeout from PHP(Wordpress)

I'm using wordpress to shared my post into linkedIn. For this i'm using https://api.linkedin.com/v2/ugcPosts API. But this API response return 504 gateway timeout.

In previous step when i called another API to get access token, its easily got the access token. But when I wanted to create a share using ucPosts POST api request it providing gateway time out. My requested code here.

Please any one help me.

Tried from localhost apache server(PHP, wordpress)

$params = '{
        "author" : "urn:li:person:'.$linkedInAppCredentials->get_user_URN().'",
        "lifecycleState" : "PUBLISHED",
        "specificContent" : {
            "com.linkedin.ugc.ShareContent" : {
                "shareCommentary" : {
                    "text" : "'.$message.'"
                },
                "shareMediaCategory" : "NONE"
            }},
        "visibility" :"PUBLIC"
}';
$headers = '{
    "Content-Type": "application/json",
    "X-Restli-Protocol-Version": "2.0.0",
    "x-li-format": "json",
    "Connection": "Keep-Alive",
    "Authorization": "Bearer '.$linkedInAppCredentials->getAccessToken().'"
}';

$requestedUrl = "https://api.linkedin.com/v2/ugcPosts?oauth2_access_token=".$this->getAccessToken();
$requestBody = array(
            'headers' => $header,
            'timeout' => 3600,
            'body' => $params
        );
 $result = wp_remote_post($requestedUrl, $requestBody);

Response: [body] => {"message":"Request timed out","status":504} [response] => Array ( [code] => 504 [message] => Gateway Timeout )

like image 713
Najmul Ahmed Avatar asked Jan 24 '26 20:01

Najmul Ahmed


1 Answers

Request timeout may be happening because LinkedIn is not able to parse the request body. So it might be a good idea to convert the requestBody to a JSON string. Giving a proper JSON input worked for me I was having the same problem.

As was happening with another person: https://stackoverflow.com/a/56786205/12578136

like image 161
Rushan Khan Avatar answered Jan 27 '26 10:01

Rushan Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!