svaithin
svaithin

Reputation: 85

v2/ugcPosts is failing /author :: \"urn:li:person:12344xxx\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n

I am trying to post to v2/ugcPosts is getting a 420 error.

Error: 422 {"message":"ERROR :: /author :: \"urn:li:person:181815873\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n","status":422}

I checked the access token and it looks good.

enter image description here

Here is the Sample code

import requests

ACCESS_TOKEN = '<Access Code>'
AUTHOR_URN = "urn:li:person:1234q3123"  # Replace with your LinkedIn person URN

url = 'https://api.linkedin.com/v2/ugcPosts'

post_data = {
    "author": AUTHOR_URN,
    "lifecycleState": "PUBLISHED",
    "specificContent": {
        "com.linkedin.ugc.ShareContent": {
            "shareCommentary": {
                "text": "This message is posted using python"
            },
            "shareMediaCategory": "NONE"
        }
    },
    "visibility": {
        "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
    }
}

headers = {
    'Authorization': f'Bearer {ACCESS_TOKEN}',
    'Content-Type': 'application/json',
    'X-Restli-Protocol-Version': '2.0.0'
}

response = requests.post(url, headers=headers, json=post_data)

if response.status_code == 201:
    print("Post shared successfully on LinkedIn!")
else:
    print("Error:", response.status_code, response.text)

I dont have access to fetch the urn. So I got the urn of the profile from the customer care.

Upvotes: 0

Views: 24

Answers (0)

Related Questions