节点J,从API获取数据

时间:2020-05-26 14:42:01

标签: javascript node.js firebase google-cloud-functions

我正在尝试使用firebase函数中的Node Js从Veryfi API中获取数据。但是当我从邮递员服务发送get请求时收到以下错误:

2020-05-26T14:38:13.052Z E getAllProcessedDocuments: TypeError: "listener" argument must be a function
    at ClientRequest.once (events.js:340:11)
    at new ClientRequest (_http_client.js:174:10)
    at Object.request (http.js:39:10)
    at Object.request (https.js:245:15)
    at Object.get (https.js:249:21)
    at exports.getAllProcessedDocuments.functions.https.onRequest (/srv/index.js:144:11)
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:16)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at _combinedTickCallback (internal/process/next_tick.js:132:7)

我的功能如下:

exports.getAllProcessedDocuments = functions.https.onRequest((request, response) => {
    console.log(JSON.stringify(response.header));

    var get_options = {
        headers: {
            "Content-Type": "multipart/form-data",
            "Accept": "application/json",
            "CLIENT-ID": "vrf02pnSzhXXXXXXXXXXXwFznuhPffEcTNSl",
            "AUTHORIZATION": "apikey yanXXck.tXXXen:6b2XXXXXXXXXXXXXXXXX65ff24248"
        }
    };

    https.get('https://api.veryfi.com/api/v7/partner/documents/', get_options, (resp) => {
        let data = '';

        // A chunk of data has been recieved.
        resp.on('data', (chunk) => {
            data += chunk;
        });

        // The whole response has been received. Print out the result.
        resp.on('end', () => {
          //  console.log(JSON.parse(data).explanation);
            return response.sendStatus(200);
        });
    }).on("error", (err) => {
        console.log("Error: " + err.message);
        return response.sendStatus(404);
    });
});

有人知道吗?

0 个答案:

没有答案