0
当我执行我的代码时,我不断收到错误'TypeError:callback不是函数'。
这是相关代码:错误:回调不是函数(nodejs)
exports.isVideo = function(tweetId, callback) {
client.get('statuses/show/' + tweetId, function(err, tweet, res){
if(tweet.extended_entities){
if(tweet.extended_entities.media[0].type === 'video'){
console.log('true');
callback(true);
} else {
console.log('false');
callback(false);
}
} else {
console.log('false');
callback(false);
}
});
}
这是一个不同的文件(我需要在这一个顶部的第一个文件,这是不是错误的原因):
ids.forEach(function(id){
console.log(id.twitterId);
twitterConverter.isVideo(id.twitterId, function(boolean){
if(boolean){
console.log('do something');
} else {
console.log('do nothing');
}
});
});
首先,请不要将其标记为重复,因为其他帖子的标题类似。我仔细观察了它们,原因通常是没有传递回调函数,或者传递了太多的参数,这里不是这种情况。
我对nodejs还没有那么有经验,所以也许我忽略了一些明显的东西,但是我找不到这个代码有什么问题。
client.get()
从this npm包。也许这个错误与此有关?
如果你能在这里帮助我,我会非常高兴。
尝试记录'typeof callback'?可能会给你一个提示。你的代码对我来说看起来很好。你确定你没有在没有回调的情况下在别的地方调用该函数吗? – otajor
typeof callback返回未定义。这很奇怪,我真的不知道它为什么不返回函数。 – eRodY
你已经在client.get()的回调中处理'err'了吗? 也许有一些错误,你的'回调'没有执行,并被视为不作为回调函数? – Carr