【发布时间】:2017-12-08 02:08:30
【问题描述】:
我的数据库中有超过 2000 个用户,当我尝试向所有用户广播消息时,它几乎没有发送大约 200 个请求,然后我的服务器停止了,我收到如下错误:
{ Error: connect ETIMEDOUT 31.13.88.4:443
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect,
address: '31.13.88.4',
port: 443 }
有时我收到另一个错误提示:
Error!: Error: socket hang up
这是我的要求:
function callSendAPI(messageData) {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: { access_token: '#####' },
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
if (messageId) {
console.log("Successfully sent message with id %s to recipient %s",
messageId, recipientId);
} else {
console.log("Successfully called Send API for recipient %s",
recipientId);
}
} else {
console.error("Failed calling Send API");
console.log(error)
}
});
}
我试过了
setTimeout 让 API 调用等待一段时间:
setTimeout(function(){callSendAPI(data)},200);
如果遇到类似错误,谁能帮忙?
已编辑
我正在使用 Messenger 平台,它支持对发送 API 的高调用率,并且不限于 200 次调用。
【问题讨论】:
-
@mplungjan 我做了,但我没有得到与 http.request 相关的答案
-
q=ETIMEDOUT+node.js+POST+facebook
-
您是否正在向 graph.facebook.com 发出 2000 个并发请求并想知道为什么会失败? :)
-
@JeremyThille 对不起!发出 2000 个请求有什么问题?我没有直接使用graph.API ..我通过没有限制的Graphs使用Messenger API。
-
哦,那不一样了,如果是messenger API就对了。
标签: javascript node.js facebook api node-request