我正在构建一个具有“使用LinkedIn登录”功能的React应用程序和Express API。我已经对OAuth进行了排序,所以现在有了访问令牌,但是当我尝试使用它来获取数据时,仍然遇到CORS问题。我可以直接从我的React应用程序(客户端)发出REST API请求吗?还是我需要通过自己的Express服务器/ API代理每个请求?
useEffect(() => {
// get linkedin data
fetch(`https://api.linkedin.com/v2/me`, {
method: 'get',
mode: 'cors',
headers: {
'Connection': 'Keep-Alive',
'Authorization': `Bearer ${accessToken}`
},
}).then(response => response.json()).then(function(data) {
console.log(data);
});
}, []);
从原点“ https://api.linkedin.com/v2/me”到“ http://localhost:3000”的获取操作已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否“ Access-Control-Allow-来源的标头出现在请求的资源上。如果不透明的响应满足您的需求,请将请求的模式设置为“ no-cors”以在禁用CORS的情况下获取资源。