I want to programmatically post the article on my LinkedIn page similar to how I manually did. Check here
A similar question was asked 3 years and 2 months ago but it's about sharing a blog article on LinkedIn. Here is the thread I'm referring.
This is what I have tried so far (both times it just shares the external URL with text on the page instead of creating this as an article. I know that's because it's intended for that purpose. But I want to create an article on my LinkedIn page like how I manually created one.
Anyone knows is LinkedIn has API for creating and posting article on linkdein page?
POST https://api.linkedin.com/v2/ugcPosts
$media = [
'status' => 'READY',
'originalUrl' => $originalUrl
];
if ($title !== '') {
$media['title'] = ['text' => $title];
}
if ($description !== '') {
$media['description'] = ['text' => $description];
}
$response = $this->getHttpClient()::withToken($this->getAccessToken()['access_token'])
->withHeaders($this->httpHeaders())
->post("$this->apiUrl/$this->apiVersion/ugcPosts", [
'author' => "urn:li:{$this->author()}:{$this->values['provider_id']}",
'lifecycleState' => 'PUBLISHED',
'specificContent' => [
'com.linkedin.ugc.ShareContent' => [
'shareCommentary' => [
'text' => $commentaryText,
],
'shareMediaCategory' => 'ARTICLE',
'media' => [$media]
]
],
'visibility' => [
'com.linkedin.ugc.MemberNetworkVisibility' => Str::upper(Arr::get($params, 'visibility', 'PUBLIC'))
],
]);
I also tried this:
POST https://api.linkedin.com/rest/posts
$articleContent = [
'article' => [
'source' => $articleSource,
'thumbnail' => $thumbnailUrn,
'title' => $title,
'description' => $description
]
];
$response = $this->getHttpClient()::withToken($this->getAccessToken()['access_token'])
->withHeaders($this->httpHeaders())
->post("https://api.linkedin.com/rest/posts", [
'author' => "urn:li:organization:{$this->values['provider_id']}",
'commentary' => $commentary,
'visibility' => Str::upper(Arr::get($params, 'visibility', 'PUBLIC')),
'distribution' => [
'feedDistribution' => 'MAIN_FEED',
'targetEntities' => [],
'thirdPartyDistributionChannels' => []
],
'content' => $articleContent,
'lifecycleState' => 'PUBLISHED',
'isReshareDisabledByAuthor' => false
]);
I used this code like 6 months ago, it worked, hope it helps