繁体   English   中英

Firebase Cloud Functions 错误:连接 ECONNREFUSED

[英]Firebase Cloud Functions Error: connect ECONNREFUSED

我正在尝试使用 Firebase Cloud Functions 根据他们的API创建一个 Kik Messenger 机器人。 我正在使用 Blaze 计划。 我正在尝试回复我的机器人收到的消息。 我可以在我的 API 上接收消息,但是当我尝试回复它们时出现错误。 错误不是来自请求回调。 我在 Firebase 控制台上看到错误。

错误:连接 ECONNREFUSED 72.14.246.44:443

在 Object.exports._errnoException (util.js:1018:11)
在 exports._exceptionWithHostPort (util.js:1041:20)
在 TCPConnectWrap.afterConnect [完成时] (net.js:1086:14)
代码:'ECONNREFUSED',
errno: 'ECONNREFUSED',
系统调用:'连接',
地址:'72.14.246.44',
端口:443

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

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');
  });
});

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

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

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

该问题也可能与您发送回复消息的方式有关。 您是否使用正确的 API 端点和格式来发送回复和所有必需的参数? 请查看 Kik Messenger API 文档,以确保您为回复消息发送正确的设计和参数。

如果您有权访问 Firebase 控制台日志,您应该能够看到有关您遇到的错误的更多详细信息。 这有助于确定问题的根本原因。 您可以尝试使用 Postman 或 curl 等工具发送测试消息,看看是否可以缩小错误原因。

如果您在尝试这些步骤后仍无法解决问题,请联系 Kik Messenger API 支持团队以获得更多帮助。 他们可以提供有关您遇到的特定错误的更多信息,并帮助您找到解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM