4

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 )

1 Answers1

1

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