'How to get all Linkedin Profile Posts with Linkedin Api
I need LinkedIn API for showing the feeds of my profile what I have posted from the day first. posts include media, images, video etc.
I had tried with LinkedIn /share endpoint but it returns an error like below,
[serviceErrorCode] => 0
[message] => Tunneled request must have 'Content-Type' header set to 'application/x-www-form-urlencoded' or 'multipart/mixed'
[status] => 400
Here is code:
$url="https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:person:".$linked_profile['id'];
$headers[] = 'X-HTTP-Method-Override: BATCH_GET';
$headers[] = 'X-Restli-Protocol-Version: 2.0.0';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Authorization: Bearer ' .$_SESSION['linkedin_access_token'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result,true);
Please help if anyone has done this before. Thanks.
Solution 1:[1]
I ran into this exact issue last night. The error message is cryptic, but it means that your body format and Content-Type header don't match. In your case, the Content-Type header says the body should be a URL encoded form but you're not sending a body at all, you're putting the form in the query parameters. If you move the query parameters to the body, it'll work.
I know this is an old post but I expect many more to hit this issue soon as LinkedIn is changing some of their APIs effective April 30, 2022. Here's a guide to migrate to the new format.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GJK |
