尝试通过API发布我的公司消息

huangapple go评论60阅读模式
英文:

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"。

令牌创建:
尝试通过API发布我的公司消息

已启用的产品:
尝试通过API发布我的公司消息

英文:

Issue: "w_organization_social" Missing during the Token Generation

Token creation:
尝试通过API发布我的公司消息

Products enabled
尝试通过API发布我的公司消息

huangapple
  • 本文由 发表于 2023年7月17日 15:58:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定