LinkedIn 公司研究 API 教程 | SandBase
用 LinkedIn 公司 URL 查询公开公司资料,并用 Python 串联公司帖子研究;说明附属页面、近期排序与分页验证边界。

做 B2B 研究或竞品情报时,拿到一个 LinkedIn 公司 URL,下一步要先分清任务:查企业资料,还是看公司发布了什么。本文用两个 SandBase 端点串联公司资料和帖子请求,并保留原来的 Python 业务读取代码,说明当时观测到的结果。想先了解端点范围,可以读 LinkedIn 公开数据 API 汇总页。
这里仅讨论公开、只读的公司数据,调用需要 SandBase API 密钥。查阅当前参考的输入和响应说明,不保证每次有全部字段。当前 profile README 已有字段说明和截短示例;后文历史 reader 的载荷字段来自我在 2026-09-28(UTC)运行的调用,仍是当时的观测,不是完整返回保证。本次编辑更新于 2026-11-06。 这次只核对公开文档并做离线测试,没有重跑 API,也不把旧测试日期改成今天。
先说结论
- 查企业信息用
company-profile,看公开页面更新用company-posts,两者用途不同。- 调用走
POST /v1/api/linkedin/web-v2/<path>,传公司url,以SANDBASE_API_KEY鉴权。- 两个端点接收同一个公司 URL;后文 reader 保留的是 2026-09-28 的观测。
- 仅公开、只读数据,不发帖,不涉及私有或仅成员可见的数据。
SandBase vs. 官方 LinkedIn API
| 你的需求 | 用 |
|---|---|
| 公开、只读的公司资料和帖子 | SandBase LinkedIn 公开数据 API |
| 管理主页、发帖,或用 Marketing/合作伙伴 API | LinkedIn 官方 API |
| 私有或仅成员可见的数据 | 两种公开方案都不适用 |
工作流一览
- 用
linkedin/web-v2/company-profile以一个公司url读资料。 - 用同一个
url调用linkedin/web-v2/company-posts拉帖子。
历史示例使用 id、status、model 和 outputs[0].data;当前 profile README 也说明了这一负载路径。
保留的历史目录截图,展示本教程使用的 company-profile 和 company-posts;不是 2026-11-06 新运行的证据。
一个公司 URL,先选资料还是帖子
查公开公司资料,向 company-profile 传带 https:// 的完整公司页 URL。当前 profile README 已说明 company_size、headquarters、followers、affiliated 和 similar 等字段。2026-11-06 读取时,文档将 Microsoft 非空示例标为真实响应的截短版本,列表只留首项,长文本也有裁剪。这是有读取日期的参考材料,不是本次新跑的结果,更不保证每次返回齐全。
affiliated 可用来找相关页面,其中可能有子公司或 showcase page,但不能据此核验法律持股关系,也不能当成完整企业架构树。similar 是另一份相似页面列表,不等于附属组织。公司员工规模区间、LinkedIn 上显示的员工数量和粉丝数也不是同一种指标。缺失字段或列表就保留未知,不填成零,更不能证明没有关联。README 中有限的员工和更新样本,不是完整清单。
研究公司近期公告,则用同一 URL 调 company-posts,不要把 profile 中的更新样本当成完整帖子来源。README 说明了 recent、top 排序,但近期排序不代表实时覆盖。可选参数类型还存在冲突,本文请求不传这些选项。
用 Python 发起公司资料请求
下面只请求 profile,走 Model API POST,不是目录 GET。密钥放服务器环境,运行前核对 company-profile 请求参考。本次未执行这段请求示例。 它只检查 HTTP 并解析 JSON,不判断应用层是否完成,也不猜字段。解码后的 JSON 原样保留,不新增业务 parser 或响应 fixture。
import os
import requests
key = os.environ.get("SANDBASE_API_KEY")
if not key:
raise RuntimeError("Set SANDBASE_API_KEY in the server environment")
resp = requests.post(
"https://api.sandbase.ai/v1/api/linkedin/web-v2/company-profile",
headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
json={"url": "https://www.linkedin.com/company/microsoft/"},
timeout=70,
)
resp.raise_for_status()
response = resp.json() # Opaque JSON; no field or envelope parser.
# Keep the response opaque; do not log the full payload by default.帖子翻页:参数说明不等于实现验证
company-posts 参考 用偏移量解释 start,并说 pagination_token 来自上一响应的 paging。这不是已验证的第二页教程。2026-11-06 读取时,README 将 start、sort_by 和 pagination_token 写为 string,FAQ 却写为 any,页面也没有展示帖子响应样例。现在不能指定 token 子字段、猜测 offset 和 token 同传的行为,更不能把文档中的偏移步长当成固定帖子数量。
发布第二页代码前,需要产品方核准正式输入类型及两种分页模式,并提供同一公司、同一排序下连续前两页的真实脱敏记录。记录要确认 token 的位置和绑定关系,日志不能泄露 token,还要验证结束页和分页不推进的行为。条件未满足,就不写续页实现,也不承诺完整历史。
第 0 步:一个辅助函数管所有调用
这个 helper 服务于保留的历史 reader。要求 dict 是为了让这些旧读取代码工作,不代表当前 posts 的通用 schema。它检查完成状态,只读文档说明的 outputs[0].data;缺失或类型错误时抛错,真正返回的空字典仍可接受。失败信息不回显上游错误内容。
import os
import requests
API = "https://api.sandbase.ai/v1/api"
HEADERS = {
"Authorization": f"Bearer {os.environ['SANDBASE_API_KEY']}",
"Content-Type": "application/json",
}
def call(path: str, payload: dict) -> dict:
resp = requests.post(f"{API}/{path}", headers=HEADERS, json=payload, timeout=70)
resp.raise_for_status()
body = resp.json()
if not isinstance(body, dict):
raise RuntimeError("SandBase response must be a JSON object")
if body.get("status") != "completed":
error = body.get("error")
if isinstance(error, dict):
error = error.get("message")
detail = "error reported" if isinstance(error, str) and error else "no error message"
raise RuntimeError(f"SandBase call did not complete ({detail})")
outputs = body.get("outputs")
if not isinstance(outputs, list) or not outputs or not isinstance(outputs[0], dict):
raise RuntimeError("SandBase response is missing valid outputs[0].data")
if "data" not in outputs[0] or not isinstance(outputs[0]["data"], dict):
raise RuntimeError("SandBase outputs[0].data must be a JSON object for this historical reader")
return outputs[0]["data"]第 1 步:读公司资料
url = "https://www.linkedin.com/company/openai"
profile = call("linkedin/web-v2/company-profile", {"url": url})
print(profile.get("company_size"), "|", profile.get("followers"), "粉丝")
print("总部:", profile.get("headquarters"))在我抓到的响应里(company-profile run id 79201745-d83f-4b1f-bee3-ba676cd1a1f0,测试于 2026-09-28,UTC),负载带 about、description、company_size、followers、employees 和 headquarters。这些是当时观测到的示例字段,用 .get() 读取,并对照真实响应核对。
保留的历史 company-profile 参考截图,不代表当前 README 的字段清单,也不是本次新测试。
第 2 步:拉公司帖子
页面更新有独立的 company-posts 请求参考。下面保留历史业务 reader,feed.get("data", []) 是当时观测到的内层列表路径,不是新建的通用负载 parser。
feed = call("linkedin/web-v2/company-posts", {"url": url})
posts = feed.get("data", [])
paging = feed.get("paging")
for p in posts[:5]:
print(p.get("num_likes"), "赞,", p.get("num_comments"), "评论 -", p.get("posted"))在我 2026-09-28(UTC)的运行里(company-posts run id acda947a-5c3e-4114-a762-b1474e333bff),负载带一个 data 帖子列表,每条有 num_likes、num_comments、num_reposts、posted 和 poster,另有一个 paging 对象。这只是带日期的观测,不等于验证了可用 token 路径或第二页;续页实现仍须满足前面的条件。
保留的历史 company-posts 参考截图,请求使用同一公司 URL;本文尚未验证下一页机制。
串起来
def research(company_url: str):
profile = call("linkedin/web-v2/company-profile", {"url": company_url})
feed = call("linkedin/web-v2/company-posts", {"url": company_url})
posts = feed.get("data", [])
engagement = [
{"posted": p.get("posted"), "likes": p.get("num_likes"), "comments": p.get("num_comments")}
for p in posts if isinstance(p, dict)
]
return {
"company_size": profile.get("company_size"),
"followers": profile.get("followers"),
"recent_posts": engagement,
}两个端点使用同一个公司 URL,历史工作流因此可以串联。但 research() 中的 .get() 路径属于 2026-09-28 观测,不是当前通用 schema。缺失的公司指标和互动计数保留为 None,不编成零;本地得到空帖子列表,也不能证明公司没有帖子。
常见用例
以下用例沿用上面的历史字段,比较记录前先确认实际可用性。
竞品情报
读一个竞品的 company_size、followers 和 headquarters,再拉近期帖子看它们推什么、效果如何(赞、评论、转发)。输入:一个公司 url。输出:企业信息加一份帖子互动样本。端点:company-profile、company-posts。
线索与客户研究
用 company-profile 的 company_size 和 followers 给目标客户名单补充企业信息,辅助排优先级。输入:公司 URL。输出:可比的企业信息。端点:company-profile。
内容与信息分析
拉一个公司的帖子,分析 poster、发帖节奏和互动,理解它的内容策略。输入:一个公司 url。输出:带互动的帖子样本。端点:company-posts。
招聘与增长信号
多次读取的 company_size 和 followers,结合帖子主题,可能提供方向性线索,但不能证明公司在增长。若自行收集可比快照,应保留日期,缺失值继续记为未知;字段可用性和排序都可能变化。输入:一个公司 url。输出:有范围限定的企业与发帖观测。端点:company-profile、company-posts。
实操要点
- 读取已说明的路径。 只读
outputs[0].data,缺失或错误时抛错,不回退到output。 - 翻页实现有前提。 等产品核准类型及连续两页真实脱敏响应,不能把旧
paging观测当成续页教程。 - 区分文档与观测。 当前 README 已说明 profile 字段;保留的 reader 仍依据历史观测,不保证每次完整返回。
- 仅公开、只读数据。 不发帖,不涉及仅成员可见数据。用 SandBase API 密钥鉴权。
- 做个好客户端。 HTTP 429 等瞬时错误需退避,不默认记录完整负载或 token。本文代码没有实现自动重试。
常见问题
我需要 LinkedIn 开发者应用或登录吗?
调用以 SANDBASE_API_KEY 向 SandBase 鉴权,当前 profile 参考说明不必单独申请 LinkedIn API 访问。本文不涵盖主页管理或私有数据。
什么标识一个公司?
带 https:// 的完整公司页 url。两个端点接收同一个 URL。
怎么翻更多帖子? 当前 README 有分页参数说明,但类型与 FAQ 冲突。发布续页代码前,须由产品核准,并用连续两页真实脱敏记录确认 token 位置、绑定关系及停止行为。本文没有建立完整历史或固定页大小的保证。
我能读成员资料或私有数据吗? 本教程只覆盖公司端点,私有和仅成员可见数据不在范围内。
小结
一个公司 URL,先分清资料和页面更新两项任务,再看标明日期的原业务 reader。完整端点目录见 LinkedIn 公开数据 API 汇总页。准备好后:
觉得有用?分享给更多人