如何在没有 JS SDK 的情况下向 LinkedIn API v2 和 OAuth 2.0 发出请求?

how to make request to LinkedIn API v2 and OAuth 2.0 without JS SDK?

我正在尝试直接从浏览器集成 LinkedIn v2 OAuth 2.0 登录,但为了解决 Ovid 跨域问题,我需要使用 JS SDK。

但我在这里看到: https://engineering.linkedin.com/blog/2018/12/developer-program-updates

从 3 月 1 日起 js SDK 将无法运行

SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps.

那么没有SDK了怎么用LinkedIn登录呢?? (而且我不能使用任何非免费或非商业的 OAuth 库)

并且我也在尝试避免为此使用服务器端

这是 V1 API 的解决方案。我不确定 API.

的 V2 是否会继续这样做

您可以使用如下参数创建 URL,但是 imagesummary 字段按预期显示存在一些问题。

  • page - 第 URL 页
  • title - 页面内容
  • summary - 内容摘要
  • source - 站点名称

这样构造 URL:(内插字符串示例)

https://www.linkedin.com/shareArticle?mini=true&url=${page}&title=${title}&summary=${summary}&source=${source}

建议,如果你控制了html元标签,可以应用以下内容,以获得更丰富的分享体验。

  <meta property="og:title" content="My Shared Article Title" />
  <meta property="og:description" content="Description of shared article" />
  <meta property="og:url" content="http://example.com/my_article.html" />
  <meta property="og:image" content="http://example.com/foo.jpg" />

来源:

Linked In - Share on LinkedIn V1 Docs

TypeScript 示例

此示例使用共享 link 创建一个新的 window。

let page = this.getPageUrl(true);
let title = this.getTagTitle(true);
let summary = this.getTagDescription(true);
let source = this.getTitle(true);

let tokenLink = `https://www.linkedin.com/shareArticle?mini=true&url=${page}&title=${title}&summary=${summary}&source=${source}`;

window.open(tokenLink);