【发布时间】:2018-02-13 12:10:14
【问题描述】:
我正在尝试使用 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 [as oncomplete] (net.js:1086:14)
代码:'ECONNREFUSED',
错误号:'ECONNREFUSED',
系统调用:“连接”,
地址:'72.14.246.44',
端口:443
对 Kik Messenger API 的请求适用于本地和远程 node/express 应用程序。我尝试在 Cloud Functions 上使用 kik-node,但结果相同。到目前为止,我发现https://auth.kik.com 解析为亚马逊,https://api.kik.com 解析为谷歌主机。我认为他们也在为他们的 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');
});
});
【问题讨论】:
-
其他出站(非 Google)API 调用是否有效?他们在灭火计划中应该没问题,但可能值得进行健全性检查。
-
是的,他们正在工作。正如您在代码中看到的那样,有 2 个不同的域,正如我所解释的,它们都针对不同的 IP。除此之外,我还尝试了不同的 API 调用,它们都有效。
-
我在尝试使用云功能在 google apis 中创建访问令牌时遇到了同样的问题。是否有可能使用端口 :80 而不是端口 :443 导致错误?
标签: node.js firebase google-cloud-functions kik