英文:
Trying to publish messages with my company via an API
问题
我正在尝试通过API发布我的公司的消息,但它不起作用。我可以直接在我的个人资料上发布,但无法代表我的组织发布到我的公司页面。
收到的错误:
帖子创建失败,状态码为403:{"serviceErrorCode":100,"message":"在REQUEST_BODY中处理字段时,数据处理异常验证失败 [/author]","status":403}
我的URN来自哪里:
https://www.linkedin.com/company/xxxxxxxx/admin/
代码:
import requests
import json
ACCESS_TOKEN = 'ACCESS_TOKEN'
company_urn = 'urn:li:organization:xxxxxxxx'
author_urn = 'urn:li:person:WMIuTv0paz'
url = 'https://api.linkedin.com/v2/ugcPosts'
headers = {
'Authorization': f'Bearer {ACCESS_TOKEN}',
'X-Restli-Protocol-Version': '2.0.0',
'Content-Type': 'application/json',
}
post_body = {
"author": f'{company_urn}',
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
response = requests.post(url, headers=headers, data=json.dumps(post_body))
if response.status_code == 201:
print('帖子创建成功!')
else:
print(f'帖子创建失败,状态码为{response.status_code}:{response.text}')
英文:
I'm trying to publish messages with my company via an API, but it doesn't work. I can do it directly with my profile on my profile, but I can't do it on behalf of my organization to post to my company page.
Error received:
Post creation failed with status code 403: {"serviceErrorCode":100,"message":"Field Value validation failed in REQUEST_BODY: Data Processing Exception while processing fields [/auth
or]","status":403}
Where does my URN come from:
https://www.linkedin.com/company/xxxxxxxx/admin/
Code:
import requests
import json
ACCESS_TOKEN = 'ACCESS_TOKEN'
company_urn = 'urn:li:organization:xxxxxxxx'
author_urn = 'urn:li:person:WMIuTv0paz'
url = 'https://api.linkedin.com/v2/ugcPosts'
headers = {
'Authorization': f'Bearer {ACCESS_TOKEN}',
'X-Restli-Protocol-Version': '2.0.0',
'Content-Type': 'application/json',
}
post_body = {
"author": f'{company_urn}',
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
response = requests.post(url, headers=headers, data=json.dumps(post_body))
if response.status_code == 201:
print('Post successfully created!')
else:
print(f'Post creation failed with status code {response.status_code}: {response.text}')
答案1
得分: 1
也许您没有代表该组织发布的权限。在这种情况下,w_organization_social
权限起了作用。
英文:
Perhaps you don't have permission to post on behalf of the organization. In this case w_organization_social
permission did the trick.
答案2
得分: 0
问题:在令牌生成期间缺少"w_organization_social"。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论