Firebase云功能错误:连接ECONNREFUSED

ben*_*nel 11 node.js firebase kik google-cloud-functions

我正在尝试使用Firebase云功能根据其API创建Kik Messenger bot .我正在使用Blaze Plan.我正在尝试回复我的机器人收到的消息.我可以在我的API上收到消息,但是当我尝试回复它们时,我收到错误消息.错误不是来自请求回调.我在Firebase控制台上看到了错误.

错误:连接ECONNREFUSED 72.14.246.44:443

at object.exports._errnoException(util.js:1018:11)
at exports._exceptionWithHostPort(util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete](net.js:1086:14)
code:'ECONNREFUSED' ,
错误号:'ECONNREFUSED',
系统调用:'connect',
地址:'72 .14.246.44',
port:443

对Kik Messenger API的请求适用于本地和远程节点/快速应用程序.我尝试在云函数上使用kik-node,但它给出了相同的结果.到目前为止我发现的是https://auth.kik.com解析到亚马逊并https://api.kik.com解析为Google Hosting.我认为他们也在使用Firebase Cloud Functions作为他们的API.它们是否可能被阻止入站请求?这是我尝试过的示例代码.

exports.messagepost = functions.https.onRequest((req, res) => {
  // Gives the error below
  // {
  //  Error: connect ECONNREFUSED 72.14.246.44:443
  //   at Object.exports._errnoException (util.js:1018:11)
  //   at exports._exceptionWithHostPort (util.js:1041:20)
  //   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
  //   code: 'ECONNREFUSED',
  //   errno: 'ECONNREFUSED',
  //   syscall: 'connect',
  //   address: '72.14.246.44',
  //   port: 443
  // }
  request.post({
    uri: 'https://api.kik.com/v1/message',
    body: JSON.stringify({
      foo: 'bar'
    }),
    json: true,
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    },
    headers: {
      'Content-Type'   : 'application/json'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});

exports.messageget = functions.https.onRequest((req, res) => {
  // Gives the error below
  // {
  //  Error: connect ECONNREFUSED 72.14.246.44:443
  //   at Object.exports._errnoException (util.js:1018:11)
  //   at exports._exceptionWithHostPort (util.js:1041:20)
  //   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
  //   code: 'ECONNREFUSED',
  //   errno: 'ECONNREFUSED',
  //   syscall: 'connect',
  //   address: '72.14.246.44',
  //   port: 443
  // }
  request.get({
    uri: 'https://api.kik.com/v1/message',
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});

exports.verificationget = functions.https.onRequest((req, res) => {
  // Runs with no errors
  request.get({
    uri: 'https://auth.kik.com/verification/v1/check',
    qs: {
      u: 'username',
      d: 'hostname',
      debug: true
    },
    body: JSON.stringify({ data: 'debugsigneddata' }),
    headers: {
      'Content-Type'   : 'application/json' ,
      'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
    },
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});

exports.verificationpost = functions.https.onRequest((req, res) => {
  // Runs with no errors
  request.post({
    uri: 'https://auth.kik.com/verification/v1/check',
    qs: {
      u: 'username',
      d: 'hostname',
      debug: true
    },
    body: JSON.stringify({ data: 'debugsigneddata' }),
    headers: {
      'Content-Type'   : 'application/json' ,
      'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
    },
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});
Run Code Online (Sandbox Code Playgroud)

Wil*_*hou 0

我在使用云功能而不是运行专用服务器实现 OAuth2 令牌交换时遇到了类似的问题。

这可能对 OP 没有帮助,但要修复我的情况下的此错误,我必须将 https:// 协议添加到我的帖子 URL,因为它丢失了。

如果其他人遇到此问题,可能需要检查您的 POST url 是否正确编写。