gpt4 book ai didi

javascript - 检索 LinkedIn 访问 token

转载 作者:数据小太阳 更新时间:2023-10-29 04:52:02 24 4
gpt4 key购买 nike

我正在尝试获取 linkedIn oauth2 访问 token ,但我坚持向 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
})

领英返回

Fetch API cannot load https: //www.linkedin.com/oauth/v2/accessToken. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: //localhost:3000' is therefore not allowed access. The response had HTTP status code 404. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

所以我尝试以“no-cors”模式发出请求。我有 200,但我无法获得响应正文,状态为 0,正文为 null 并且 response.json() 抛出 SyntaxError:输入意外结束。

最佳答案

对于遇到此问题的任何人。我们通过将数据从 LinkedIn(代码)传递到我们的后端来解决它。后端无需发送任何预检 OPTIONS 请求,并且可以毫无问题地获取访问 token 。

关于javascript - 检索 LinkedIn 访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46317202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com