简体   繁体   English

如何使用 Linkedin Api 获取所有 Linkedin 个人资料帖子

[英]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.我需要 LinkedIn API 来显示我从第一天开始发布的个人资料提要。 posts include media, images, video etc.帖子包括媒体、图片、视频等。

I had tried with LinkedIn /share endpoint but it returns an error like below,我曾尝试使用 LinkedIn /share端点,但它返回如下错误,

( https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#find-shares-by-owner ) ( https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api?tabs=http#find-shares-by-owner )

[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.谢谢。

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.错误消息是含糊不清的,但这意味着您的正文格式和Content-Type header 不匹配。 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.在您的情况下, Content-Type header 表示主体应该是 URL 编码形式,但您根本没有发送主体,而是将表单放入查询参数中。 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.我知道这是一篇旧帖子,但我希望随着 LinkedIn 更改他们的一些 API(自 2022 年 4 月 30 日起生效),很快会有更多人解决这个问题。 这是迁移到新格式的指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM