通过node.js服务器上的http请求获取LinkedIn访问令牌
我正在遵循文档,现在是第3步,我需要使用授权码从LinkedIn接收访问令牌。在这个项目中,我使用node.js、typescript和库。下面的函数创建一个内容类型为x-www——form urlencoded的主体,因为这是LinkedIn需要的内容类型通过node.js服务器上的http请求获取LinkedIn访问令牌,node.js,typescript,linkedin,node-fetch,Node.js,Typescript,Linkedin,Node Fetch,我正在遵循文档,现在是第3步,我需要使用授权码从LinkedIn接收访问令牌。在这个项目中,我使用node.js、typescript和库。下面的函数创建一个内容类型为x-www——form urlencoded的主体,因为这是LinkedIn需要的内容类型 async function GetAccessToken(data: any) { let body: string | Array<string> = new Array<string>();
async function GetAccessToken(data: any) {
let body: string | Array<string> = new Array<string>();
for (let property in data) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(data[property]);
body.push(encodedKey + "=" + encodedValue);
}
body = body.join("&");
const response = await fetch("https://www.linkedin.com/oauth/v2/accessToken", {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
body: body
}).then((res: any) => {
console.log("Result", res);
});
return response;
}
LinkedIn的承诺是:
access_token
expires_in
当我使用postman发布带有参数的url时,请求将通过,并且我收到了正确的数据,这表明问题出在我的请求函数中,而不是我的值中
感谢您的帮助
access_token
expires_in