首页 > 解决方案 > 使用 Share API v2 发布到 LinkedIn 时出现 HTTP 响应错误

问题描述

我正在尝试使用 OAuth v2 向 LinkedIn 发布共享 - 我已正确获得授权并拥有适当的访问密钥。这段代码应该在 LinkedIn 上共享一个链接,但由于某种原因它不起作用 - 我不确定为什么。任何人都可以帮忙吗?这是我的请求正文:

{
  "distribution": {
      "linkedInDistributionTarget": {}
  },
  "owner": "urn:li:person:XXXXXX",
  "subject": "Test Share Subject",
  "text": {
      "text": "Hello !"
  }

这是我的呼叫 API 共享:

  publishPostLink(body : any, token : any){
this.headers = new HttpHeaders(
  {
    'Content-Type': 'application/json',
    'Authorization':'Bearer '+token, 
    'cache-control': 'no-cache', 
    'X-Restli-Protocol-Version':'2.0.0', });    
return this.http.post("https://api.linkedin.com/v2/shares" , body, {headers: this.headers});}

我得到这个问题:

我已经安装了 Moesif CORS 但它没有用

我使用这篇文章修复了错误.. 它应该使用后端而不是前端的 REST API

标签: apirestlinkedinangular9linkedin-api

解决方案


http://localhost 是一个不安全的请求来源,因此在许多情况下不受支持。尝试使用 Ngork https://ngrok.com/之类的隧道软件


推荐阅读