小编erh*_*dos的帖子

检索LinkedIn访问令牌

我正在尝试获取linkedIn oauth2访问令牌,但我坚持向https://www.linkedin.com/oauth/v2/accessToken发出最后请求

const body = new URLSearchParams([
  ['grant_type', 'authorization_code'],
  ['code', code],
  ['redirect_uri', 'http://localhost:3000/'],
  ['client_id', CLIENT_ID],
  ['client_secret', CLIENT_SECRET]
]);
const headers = new Headers({'Content-Type': 'x-www-form-urlencoded'}); 

window.fetch('https://www.linkedin.com/oauth/v2/accessToken', method: 'POST',body, headers)
.then(response => response.json())
.then(data => {
// rest of code
})
Run Code Online (Sandbox Code Playgroud)

LinkedIn返回

Fetch API无法加载https://www.linkedin.com/oauth/v2/accessToken.对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源'http:// localhost:3000'访问.响应具有HTTP状态代码404.如果不透明响应满足您的需要,请将请求的模式设置为"no-cors"以获取禁用CORS的资源.

所以我试图以'无人'模式提出请求.我有200但是我无法得到响应体,状态为0,body为null并且response.json()抛出SyntaxError:意外的输入结束.

javascript oauth linkedin oauth-2.0

8
推荐指数
1
解决办法
950
查看次数

标签 统计

javascript ×1

linkedin ×1

oauth ×1

oauth-2.0 ×1