linkedin

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Call the LinkedIn API with
curl + jq
. The user's bearer token is in
$LINKEDIN_TOKEN
; every call needs
Authorization: Bearer $LINKEDIN_TOKEN
.
LinkedIn posts must be authored by the member's URN. Get the member id from the OpenID userinfo endpoint, then build
urn:li:person:{sub}
.
bash
SUB=$(curl -sS -H "Authorization: Bearer $LINKEDIN_TOKEN" \
  "https://api.linkedin.com/v2/userinfo" | jq -r .sub)
AUTHOR="urn:li:person:$SUB"
echo "$AUTHOR"
Errors are JSON with
message
/
serviceErrorCode
— show them verbatim.
401
→ token expired (tokens last ~60 days), re-connect the LinkedIn connector.
使用
curl + jq
调用LinkedIn API。用户的Bearer令牌存储在
$LINKEDIN_TOKEN
中;每次调用都需要带上
Authorization: Bearer $LINKEDIN_TOKEN
头。
LinkedIn帖子必须由成员的URN创作。从OpenID用户信息端点获取成员ID,然后构建
urn:li:person:{sub}
bash
SUB=$(curl -sS -H "Authorization: Bearer $LINKEDIN_TOKEN" \
  "https://api.linkedin.com/v2/userinfo" | jq -r .sub)
AUTHOR="urn:li:person:$SUB"
echo "$AUTHOR"
错误信息为包含
message
/
serviceErrorCode
的JSON格式——直接显示原始内容。
401
错误表示令牌过期(令牌有效期约60天),需重新连接LinkedIn连接器。

Publish a post (Posts API)

发布帖子(Posts API)

Confirm the text with the user first. Use the versioned Posts API; set the
LinkedIn-Version
header to a recent
YYYYMM
(LinkedIn requires a valid recent version — if you get
426
/version errors, bump to the current month).
bash
jq -n --arg a "$AUTHOR" --arg t "My update text. Check out https://studio.acedata.cloud" \
  '{author:$a, commentary:$t, visibility:"PUBLIC",
    distribution:{feedDistribution:"MAIN_FEED", targetEntities:[], thirdPartyDistributionChannels:[]},
    lifecycleState:"PUBLISHED", isReshareDisabledByAuthor:false}' \
| curl -sS -X POST "https://api.linkedin.com/rest/posts" \
    -H "Authorization: Bearer $LINKEDIN_TOKEN" \
    -H "Content-Type: application/json" \
    -H "LinkedIn-Version: 202401" \
    -H "X-Restli-Protocol-Version: 2.0.0" \
    -d @- -D - -o /dev/null | tr -d '\r' | awk '/^[Xx]-[Rr]estli-[Ii]d:|^[Ll]ocation:/{print}'
A successful create returns
201
with the post URN in the
x-restli-id
(or
Location
) response header — report that URN / the resulting post URL.
Link posts: put the URL inline in
commentary
(LinkedIn auto-unfurls it). Rich article attachments need the assets/images API — out of scope for a simple text/link share; keep links inline.
**请先与用户确认文本内容。**使用版本化的Posts API;将
LinkedIn-Version
头设置为最近的
YYYYMM
格式(LinkedIn要求使用有效的最新版本——如果遇到
426
/版本错误,更新为当前月份)。
bash
jq -n --arg a "$AUTHOR" --arg t "My update text. Check out https://studio.acedata.cloud" \
  '{author:$a, commentary:$t, visibility:"PUBLIC",
    distribution:{feedDistribution:"MAIN_FEED", targetEntities:[], thirdPartyDistributionChannels:[]},
    lifecycleState:"PUBLISHED", isReshareDisabledByAuthor:false}' \
| curl -sS -X POST "https://api.linkedin.com/rest/posts" \
    -H "Authorization: Bearer $LINKEDIN_TOKEN" \
    -H "Content-Type: application/json" \
    -H "LinkedIn-Version: 202401" \
    -H "X-Restli-Protocol-Version: 2.0.0" \
    -d @- -D - -o /dev/null | tr -d '\r' | awk '/^[Xx]-[Rr]estli-[Ii]d:|^[Ll]ocation:/{print}'
创建成功会返回
201
状态码,并在
x-restli-id
(或
Location
)响应头中包含帖子URN——请告知用户该URN及生成的帖子URL。
链接帖子:将URL直接嵌入
commentary
中(LinkedIn会自动展开链接预览)。 富文本文章附件需要使用assets/images API——这超出了简单文本/链接分享的范围,直接将链接嵌入文本即可。

Fallback: legacy ugcPosts

备选方案:旧版ugcPosts

If the versioned endpoint is unavailable for the app, the older
POST https://api.linkedin.com/v2/ugcPosts
with a
specificContent."com.linkedin.ugc.ShareContent"
body also works with
w_member_social
. Prefer
/rest/posts
above.
如果版本化端点对应用不可用,使用旧版
POST https://api.linkedin.com/v2/ugcPosts
接口,搭配
specificContent."com.linkedin.ugc.ShareContent"
请求体,同时需要
w_member_social
权限。优先使用上述
/rest/posts
接口。

Gotchas

注意事项

  • Author URN must match the token's member (
    urn:li:person:{sub}
    ) — you can't post as someone else.
  • w_member_social
    only allows posting to the member's own feed; company Page posts need
    w_organization_social
    + an admin role (not in this connector).
  • The
    LinkedIn-Version
    header is mandatory for
    /rest/*
    ; a stale value returns a version error — bump to the current
    YYYYMM
    .
  • 作者URN必须与令牌所属成员匹配(
    urn:li:person:{sub}
    )——你不能以他人身份发布帖子。
  • w_member_social
    权限仅允许发布到成员个人动态;发布到公司主页需要
    w_organization_social
    权限+管理员角色(本连接器不支持此功能)。
  • /rest/*
    接口必须携带
    LinkedIn-Version
    头;如果头值过时会返回版本错误——更新为当前的
    YYYYMM
    格式。

Record the output

记录输出

After you successfully publish and obtain the live result URL, call the built-in
publish_artifact
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifact(kind="article", channel="linkedin", title="<title>", url="<the REAL returned URL>", status="delivered")
Use the real returned URL — never fabricate one. Call it once per published item, only after delivery is confirmed; skip it (or use
status="failed"
) if publishing failed. See
_shared/artifacts.md
.
成功发布并获取实时结果URL后,调用内置的
publish_artifact
工具一次,以便用户在我的输出中跟踪此交付物:
publish_artifact(kind="article", channel="linkedin", title="<title>", url="<the REAL returned URL>", status="delivered")
请使用实际返回的URL——切勿伪造。每个发布项仅调用一次,且仅在确认交付后调用;如果发布失败,请跳过调用(或使用
status="failed"
)。详情请查看
_shared/artifacts.md