除了发出新的推文而不是回复以外,其他所有方法都可以正常工作,我不确定应该在代码中添加什么以使其直接回复,非常感谢。
var TwitterPackage = require('twitter');
var secret = {
consumer_key: 'xxx',
consumer_secret: 'xxx',
access_token_key: 'xxx',
access_token_secret: 'xxx'
}
var Twitter = new TwitterPackage(secret);
// Call the stream function and pass in 'statuses/filter', our filter object, and our callback
Twitter.stream('statuses/filter', {track: 'xx'}, function(stream) {
// ... when we get tweet data...
stream.on('data', function(tweet) {
// print out the text of the tweet that came in
console.log(tweet.text);
//build our reply object
var statusObj = {status: "x@" + tweet.user.screen_name + ", xx"}
//call the post function to tweet something
Twitter.post('statuses/update', statusObj, function(error, tweetReply, response){
//if we get an error print it out
if(error){
console.log(error);
}
//print the text of the tweet we sent out
console.log(tweetReply.text);
});
});
// ... when we get an error...
stream.on('error', function(error) {
//print out the error
console.log(error);
});
});