|
通过托管 OAuth 认证访问 LinkedIn API。发布帖子、管理广告活动、获取个人资料和组织信息、上传媒体文件以及访问广告库。
bash
https://gateway.maton.ai/linkedin/rest/{resource}
网关将请求代理至 api.linkedin.com,并自动注入您的 OAuth 令牌。
所有请求都需要在 Authorization 标头中携带 Maton API 密钥:
Authorization: Bearer $MATONAPIKEY
环境变量: 将您的 API 密钥设置为 MATONAPIKEY:
bash
export MATONAPIKEY=YOURAPIKEY
LinkedIn REST API 需要版本标头:
LinkedIn-Version: 202506
在 https://ctrl.maton.ai 管理您的 LinkedIn OAuth 连接。
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections?app=linkedin&status=ACTIVE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
bash
python <
data = json.dumps({app: linkedin}).encode()
req = urllib.request.Request(https://ctrl.maton.ai/connections, data=data, method=POST)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Content-Type, application/json)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id})
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
json
{
connection: {
connection_id: ba10eb9e-b590-4e95-8c2e-3901ff94642a,
status: ACTIVE,
creation_time: 2026-02-07T08:00:24.372659Z,
lastupdatedtime: 2026-02-07T08:05:16.609085Z,
url: https://connect.maton.ai/?session_token=...,
app: linkedin,
metadata: {}
}
}
在浏览器中打开返回的 url 以完成 OAuth 授权。
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id}, method=DELETE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果您有多个 LinkedIn 连接,请使用 Maton-Connection 标头指定要使用的连接:
bash
python <
req = urllib.request.Request(https://gateway.maton.ai/linkedin/rest/me)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(LinkedIn-Version, 202506)
req.add_header(Maton-Connection, ba10eb9e-b590-4e95-8c2e-3901ff94642a)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最早)的活动连接。
bash
GET /linkedin/rest/me
LinkedIn-Version: 202506
示例:
bash
python <
req = urllib.request.Request(https://gateway.maton.ai/linkedin/rest/me)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(LinkedIn-Version, 202506)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
json
{
firstName: {
localized: {en_US: John},
preferredLocale: {country: US, language: en}
},
localizedFirstName: John,
lastName: {
localized: {en_US: Doe},
preferredLocale: {country: US, language: en}
},
localizedLastName: Doe,
id: yrZCpj2Z12,
vanityName: johndoe,
localizedHeadline: Software Engineer at Example Corp,
profilePicture: {
displayImage: urn:li:digitalmediaAsset:C4D00AAAAbBCDEFGhiJ
}
}
bash
POST /linkedin/rest/posts
Content-Type: application/json
LinkedIn-Version: 202506
{
author: urn:li:person:{personId},
lifecycleState: PUBLISHED,
visibility: PUBLIC,
commentary: Hello LinkedIn! This is my first API post.,
distribution: {
feedDistribution: MAIN_FEED
}
}
响应: 201 Created,包含包含帖子 URN 的 x-restli-id 标头。
bash
POST /linkedin/rest/posts
Content-Type: application/json
LinkedIn-Version: 202506
{
author: urn:li:person:{personId},
lifecycleState: PUBLISHED,
visibility: PUBLIC,
commentary: Check out this great article!,
distribution: {
feedDistribution: MAIN_FEED
},
content: {
article: {
source: https://example.com/article,
title: Article Title,
description: Article description here
}
}
}
首先,初始化图片上传,然后上传图片,最后创建帖子。
步骤 1:初始化图片上传
bash
POST /linkedin/rest/images?action=initializeUpload
Content-Type: application/json
LinkedIn-Version: 202506
{
initializeUploadRequest: {
owner: urn:li:person:{personId}
}
}
响应:
json
{
value: {
uploadUrlExpiresAt: 1770541529250,
uploadUrl: https://www.linkedin.com/dms-uploads/...,
image: urn:li:image:D4D10AQH4GJAjaFCkHQ
}
}
步骤 2:上传图片二进制数据
bash
PUT {uploadUrl from step 1}
Content-Type: image/png
{binary image data}
步骤 3:创建图片帖子
bash
POST /linkedin/rest/posts
Content-Type: application/json
LinkedIn-Version: 202506
{
author: urn:li:person:{personId},
lifecycleState: PUBLISHED,
visibility: PUBLIC,
commentary: Check out this image!,
distribution: {
feedDistribution: MAIN_FEED
},
content: {
media: {
id: urn:li:image:D4D10AQH4GJAjaFCkHQ,
title: Image Title
}
}
}
| 值 | 描述 |
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 linkedin-api-1776373581 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 linkedin-api-1776373581 技能
skillhub install linkedin-api-1776373581
文件大小: 9.37 KB | 发布时间: 2026-4-17 15:14