0

I tried making posts on LinkedIn using the Share on LinkedIn API. While posts made with only text involved showed up on LinkedIn as expected, the problem occurs when I try to make a post with image and text in it.

Now, the response to this request suggests that the post was made successfully. Notifications and Analytics on LinkedIn suggest that the post was made. However, the post is not there on my profile, activity or feed, and when I asked others to check their LinkedIn for any posts from me, they couldn't find these posts either.

For reference, I am making the requests on a Colab notebook, and the image was registered and uploaded on LinkedIn successfully before I made the request for the post.

Here is the code for the request.

url4_image_post = "https://api.linkedin.com/v2/ugcPosts"

data_image_post = {
    "author": author_urn,
    "lifecycleState": "PUBLISHED",
    "specificContent": {
        "com.linkedin.ugc.ShareContent": {
            "shareCommentary": {
                "text": text
            },
            "shareMediaCategory": "IMAGE", # Change from NONE to IMAGE
            "media": [
                {
                    "status": "READY",
                    "description": {
                        "text": "Work in progress"
                    },
                    "media": upload_urn # Include the image asset URN here
                }
            ]
        }
    },
    "visibility": {
        "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
    }
}
r4_image_post = requests.post(url4_image_post, headers=headers, json=data_image_post)

# Print the response to see if the post was successful
print(r4_image_post.status_code)
print(r4_image_post.content)

The status code for the request was 201, and the content for the response gives the URN for the post.

4
  • Have you tried specifying the feedDistribution you want? learn.microsoft.com/en-us/linkedin/compliance/integrations/… - "feedDistribution: Specifies the type of feed distribution. Does not distribute to feed when missing." Commented Sep 25 at 6:28
  • I tried and the response was a status code 403. Turns out the feedDistribution parameter is not available with the Share on LinkedIn API. Commented Sep 25 at 8:17
  • The schema mentions distribution and links to the section I referred to, so I guess you'd have to nest them - feedDistribution is one of the possible sub-properties of distribution? "distribution": { "feedDistribution": "..." } Commented Sep 25 at 8:20
  • The response I got was for the request where I nested feedDistribution inside distribution. Commented Sep 25 at 8:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.