我目前在上传图片并将其发布到LinkedIn feed时遇到了一些麻烦。 当我将图像上传到从 / v2 / assets?action = registerUpload 端点收到的上传网址时,收到201响应。但是,当我随后发布到LinkedIn(具有图像为URN的富媒体帖子)时,即使我从 / v2 / shares 端点获得了201,也没有在我的Feed中显示任何帖子。
我认为将图片上传到给定的上传网址的方式存在问题,因为当我使用 / v2 / assets / [URN] 查询上传的资产时会收到此响应:
这是到目前为止我尝试上传的内容:
# Upload the image
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/binary"
}
with open("virtualbadge.png", "rb") as file:
r = requests.put(upload_url, files={"file": open("myImage.png", "rb")}, headers=headers)
共享:
# Share post
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
payload = {
"content": {
"contentEntities": [
{
"entity": image_urn,
}
],
"title": "My Post Title",
"shareMediaCategory": "RICH",
"description": "My Description",
},
"distribution": {
"linkedInDistributionTarget": {}
},
"subject": "My Subject",
"text": {
text": "My Text",
},
"owner": f"urn:li:person:{user_id}",
}
share_post = requests.post("https://api.linkedin.com/v2/shares", data=json.dumps(payload), headers=headers)
任何帮助将不胜感激!