Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCall the LinkedIn API with . The user's bearer token is in
; every call needs .
curl + jq$LINKEDIN_TOKENAuthorization: Bearer $LINKEDIN_TOKENLinkedIn 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 / — show them verbatim.
→ token expired (tokens last ~60 days), re-connect the LinkedIn connector.
messageserviceErrorCode401使用调用LinkedIn API。用户的Bearer令牌存储在中;每次调用都需要带上头。
curl + jq$LINKEDIN_TOKENAuthorization: Bearer $LINKEDIN_TOKENLinkedIn帖子必须由成员的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"错误信息为包含/的JSON格式——直接显示原始内容。错误表示令牌过期(令牌有效期约60天),需重新连接LinkedIn连接器。
messageserviceErrorCode401Publish a post (Posts API)
发布帖子(Posts API)
Confirm the text with the user first. Use the versioned Posts API; set the
header to a recent (LinkedIn requires a valid recent
version — if you get /version errors, bump to the current month).
LinkedIn-VersionYYYYMM426bash
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 with the post URN in the
(or ) response header — report that URN / the resulting post URL.
201x-restli-idLocationLink posts: put the URL inline in(LinkedIn auto-unfurls it). Rich article attachments need the assets/images API — out of scope for a simple text/link share; keep links inline.commentary
**请先与用户确认文本内容。**使用版本化的Posts API;将头设置为最近的格式(LinkedIn要求使用有效的最新版本——如果遇到/版本错误,更新为当前月份)。
LinkedIn-VersionYYYYMM426bash
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}'创建成功会返回状态码,并在(或)响应头中包含帖子URN——请告知用户该URN及生成的帖子URL。
201x-restli-idLocation链接帖子:将URL直接嵌入中(LinkedIn会自动展开链接预览)。 富文本文章附件需要使用assets/images API——这超出了简单文本/链接分享的范围,直接将链接嵌入文本即可。commentary
Fallback: legacy ugcPosts
备选方案:旧版ugcPosts
If the versioned endpoint is unavailable for the app, the older
with a
body also works with
. Prefer above.
POST https://api.linkedin.com/v2/ugcPostsspecificContent."com.linkedin.ugc.ShareContent"w_member_social/rest/posts如果版本化端点对应用不可用,使用旧版接口,搭配请求体,同时需要权限。优先使用上述接口。
POST https://api.linkedin.com/v2/ugcPostsspecificContent."com.linkedin.ugc.ShareContent"w_member_social/rest/postsGotchas
注意事项
- Author URN must match the token's member () — you can't post as someone else.
urn:li:person:{sub} - only allows posting to the member's own feed; company Page posts need
w_member_social+ an admin role (not in this connector).w_organization_social - The header is mandatory for
LinkedIn-Version; a stale value returns a version error — bump to the current/rest/*.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
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifactpublish_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 ) if publishing failed.
See .
status="failed"_shared/artifacts.md成功发布并获取实时结果URL后,调用内置的工具一次,以便用户在我的输出中跟踪此交付物:
publish_artifactpublish_artifact(kind="article", channel="linkedin", title="<title>", url="<the REAL returned URL>", status="delivered")请使用实际返回的URL——切勿伪造。每个发布项仅调用一次,且仅在确认交付后调用;如果发布失败,请跳过调用(或使用)。详情请查看。
status="failed"_shared/artifacts.md