Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过node.js服务器上的http请求获取LinkedIn访问令牌_Node.js_Typescript_Linkedin_Node Fetch - Fatal编程技术网

通过node.js服务器上的http请求获取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>();

我正在遵循文档,现在是第3步,我需要使用授权码从LinkedIn接收访问令牌。在这个项目中,我使用node.js、typescript和库。下面的函数创建一个内容类型为x-www——form urlencoded的主体,因为这是LinkedIn需要的内容类型

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