在我的时间轴上的linkedin上看不到使用带有/ugcPosts端点的create image share API创建的帖子 [英] Post created using create image share API with /ugcPosts endpoint is not visible on linkedin on my timeline

查看:88
本文介绍了在我的时间轴上的linkedin上看不到使用带有/ugcPosts端点的create image share API创建的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用下面介绍的create image share api实现了在linkedin上共享图像帖子的所有三个步骤.但是创建的帖子在我的Linkedin提要/帖子或最近的活动上不可见.

已发布可见的发布网址: https://www.linkedin.com/feed/update/urn :li:share:6520269375554060288/

使用以下相同代码创建的第二次以后,将返回类似的响应,其中包含已创建的帖子ID和201已创建的状态代码,但该帖子在linkedin上不可见.

例如这篇文章 https://www.linkedin.com/feed/update/urn: li:share:6521027773560119296

我检查了我的linkedin个人资料,但在任何地方都找不到我的帖子.

我正在使用的发布最终功能代码(使用上面的文档链接创建图像共享的第三步):

 def share_on_linkedin(self, asset, title, description):
    # asset = "urn:li:digitalmediaAsset:C5122AQEAatG9rZ7MhQ"

    headers = {
    'Content-Type':'application/json',
    'X-Restli-Protocol-Version': '2.0.0',
    'Authorization': 'Bearer '+Constant.ACCESS_TOKEN
    }
    payload = {
        "author": "urn:li:person:leRbOTCFKK",
        "lifecycleState": "PUBLISHED",
        "specificContent": {
            "com.linkedin.ugc.ShareContent": {
                "shareCommentary": {
                    "text": description
                },
                "shareMediaCategory": "IMAGE",
                "media": [
                    {
                        "status": "READY",
                        "description": {
                            "text": "Center stage!"
                        },
                        "media": asset,
                        "title": {
                            "text": title
                        }
                    }
                ]
            }
        },
        "visibility": {
            "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
        }
    }

    try:
        data = json.dumps(payload, sort_keys=True, indent=4)
        url = "https://api.linkedin.com/v2/ugcPosts"
        response = requests.post(url , headers=headers, data=data )
        print response.text

        result = json.loads(response.text)  
        if response.status_code==200 or response.status_code==201:
            print response.text
            print response.headers              
            posted_url =  "https://www.linkedin.com/feed/update/"+result['id']
                            print posted_url 
            return True, posted_url
        return False, None

    except Exception as e:
        print e

输出:

{"id":"urn:li:share:6521245116978552832"}
{'Content-Length': '41', 'X-RestLi-Protocol-Version': '2.0.0', 'X-Li-Pop': 'prod-tmu1', 'X-LI-ResponseOrigin': 'RGW', 'X-RestLi-Id': 'urn:li:share:6521245116978552832', 'X-LI-UUID': 'aKr30Z+1kxWAo4kEzioAAA==', 'X-LI-Route-Key': '"b=SB83:g=115:u=3:i=1554785994:t=1554872227:s=AQH26er48VUD_YiXQIgAqujebI53eswQ"', 'X-Li-Fabric': 'prod-lsg1', 'Connection': 'keep-alive', 'Location': '/ugcPosts/urn%3Ali%3Ashare%3A6521245116978552832', 'Set-Cookie': 'lidc="b=SB83:g=115:u=3:i=1554785994:t=1554872227:s=AQH26er48VUD_YiXQIgAqujebI53eswQ"', 'Date': 'Tue, 09 Apr 2019 04:59:55 GMT', 'X-LI-Proto': 'http/1.1', 'Content-Type': 'application/json'}

根据上述成功响应构造的发布网址为: https://www.linkedin.com/feed/update/urn: li:share:6521245116978552832

但是此帖子不可见.

有人可以帮我这个忙吗?

谢谢!

解决方案

在提交ugcPosts请求之前,您可能需要验证媒体资产是否可用并准备好发布.

上传图像二进制文件后,向/assets API提交请求,并检查其状态为 Available

GET https://api.linkedin.com/v2/assets/C5122AQEAatG9rZ7MhQ

I have implemented all three steps for sharing an image post on linkedin using create image share api described below. But created posts are not visible on my linkedin feed/posts or recent activities.

https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin#create-an-image-share

First time I created the post is visible using API and it returned {"id":"urn:li:share:6521244543193575424"} Posted Visible post url: https://www.linkedin.com/feed/update/urn:li:share:6520269375554060288/

Second time onwards created with same code below returns similar response with created post id and with 201 created status code but post is not visible on linkedin.

For example this post https://www.linkedin.com/feed/update/urn:li:share:6521027773560119296

I checked my linkedin profile but couldn't find my posts any where.

Code for Final function for posting I am using(3rd step for creating image share using the documentation link above) :

 def share_on_linkedin(self, asset, title, description):
    # asset = "urn:li:digitalmediaAsset:C5122AQEAatG9rZ7MhQ"

    headers = {
    'Content-Type':'application/json',
    'X-Restli-Protocol-Version': '2.0.0',
    'Authorization': 'Bearer '+Constant.ACCESS_TOKEN
    }
    payload = {
        "author": "urn:li:person:leRbOTCFKK",
        "lifecycleState": "PUBLISHED",
        "specificContent": {
            "com.linkedin.ugc.ShareContent": {
                "shareCommentary": {
                    "text": description
                },
                "shareMediaCategory": "IMAGE",
                "media": [
                    {
                        "status": "READY",
                        "description": {
                            "text": "Center stage!"
                        },
                        "media": asset,
                        "title": {
                            "text": title
                        }
                    }
                ]
            }
        },
        "visibility": {
            "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
        }
    }

    try:
        data = json.dumps(payload, sort_keys=True, indent=4)
        url = "https://api.linkedin.com/v2/ugcPosts"
        response = requests.post(url , headers=headers, data=data )
        print response.text

        result = json.loads(response.text)  
        if response.status_code==200 or response.status_code==201:
            print response.text
            print response.headers              
            posted_url =  "https://www.linkedin.com/feed/update/"+result['id']
                            print posted_url 
            return True, posted_url
        return False, None

    except Exception as e:
        print e

Output:

{"id":"urn:li:share:6521245116978552832"}
{'Content-Length': '41', 'X-RestLi-Protocol-Version': '2.0.0', 'X-Li-Pop': 'prod-tmu1', 'X-LI-ResponseOrigin': 'RGW', 'X-RestLi-Id': 'urn:li:share:6521245116978552832', 'X-LI-UUID': 'aKr30Z+1kxWAo4kEzioAAA==', 'X-LI-Route-Key': '"b=SB83:g=115:u=3:i=1554785994:t=1554872227:s=AQH26er48VUD_YiXQIgAqujebI53eswQ"', 'X-Li-Fabric': 'prod-lsg1', 'Connection': 'keep-alive', 'Location': '/ugcPosts/urn%3Ali%3Ashare%3A6521245116978552832', 'Set-Cookie': 'lidc="b=SB83:g=115:u=3:i=1554785994:t=1554872227:s=AQH26er48VUD_YiXQIgAqujebI53eswQ"', 'Date': 'Tue, 09 Apr 2019 04:59:55 GMT', 'X-LI-Proto': 'http/1.1', 'Content-Type': 'application/json'}

Posted url constructed from above successful response is: https://www.linkedin.com/feed/update/urn:li:share:6521245116978552832

But this post is not visible.

Can anybody help me with this.

Thanks!

解决方案

You may need to verify your media asset is available and ready to be posted before submitting your ugcPosts request.

After you've uploaded your image binary, submit a request to the /assets API and check the status is AVAILABLE

GET https://api.linkedin.com/v2/assets/C5122AQEAatG9rZ7MhQ

这篇关于在我的时间轴上的linkedin上看不到使用带有/ugcPosts端点的create image share API创建的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆