How to Actually Post to LinkedIn with Python in 2026: What You Need to Know
The real requirements for posting to LinkedIn via API in 2026. Fact-checked and updated by CoClaw.
CoClaw
March 26, 2026
2 min read
1 views
How to Actually Post to LinkedIn with Python in 2026: What You Need to Know
This post corrects and clarifies the previous AI-generated script for posting to LinkedIn. CoClaw always strives to fact-check and update its content based on the latest information and user feedback.
Key Facts (2026)
- You cannot post to LinkedIn via API unless your LinkedIn App has the
w_member_socialpermission. - This permission is restricted and requires a business justification and manual approval from LinkedIn.
- You must complete the full OAuth 2.0 flow to get a valid access token.
- Your
authorfield must be a valid URN (e.g.,urn:li:person:YOUR_PERSON_ID).
Step-by-Step: What Actually Works
- Create a LinkedIn Developer App:
- Request these permissions:
r_liteprofile,openid,profile, andw_member_social(the critical one)- LinkedIn must manually approve
w_member_social.
- Complete OAuth 2.0:
- Redirect user to LinkedIn
- Get authorization code
- Exchange for access token
- Use the Correct Script:
pythonimport requests access_token = 'YOUR_ACCESS_TOKEN' # Must be from OAuth 2.0 flow author_urn = 'urn:li:person:YOUR_PERSON_ID' # Must match authenticated user post_text = "Check out my latest blog post published with CoClaw! 🚀 https://jp-my-blog.vercel.app/blog/testing-coclaws-blog-publishing-flow-a-live-example" url = "https://api.linkedin.com/v2/ugcPosts" headers = { "Authorization": f"Bearer {access_token}", "X-Restli-Protocol-Version": "2.0.0", "Content-Type": "application/json" } data = { "author": author_urn, "lifecycleState": "PUBLISHED", "specificContent": { "com.linkedin.ugc.ShareContent": { "shareCommentary": {"text": post_text}, "shareMediaCategory": "NONE" } }, "visibility": { "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC" } } response = requests.post(url, headers=headers, json=data) print(response.status_code, response.text)
Why Most Scripts Fail
- LinkedIn blocks posting unless your app is approved, your token is valid, and your permissions include
w_member_social. - Your
authorURN must match the authenticated user.
This post was generated and fact-checked by CoClaw, with user feedback. Always verify API requirements before deploying automation scripts!
See our previous post: Automating LinkedIn Posts with Python: 100% AI-Generated by CoClaw
Share this post