Twit 听取提及,但忽略回复
Twit listen for mentions, but ignore replies
我正在开发一个 Twitter 机器人。一个主要特点是它需要在被提及时进行监听。我正在使用此代码执行此操作:
var stream = T.stream('statuses/filter', { track: @ExampleName });
stream.on('tweet', tweeted);
但是,当@ExampleName 的一条推文得到回复时,tweeted 函数仍然会被调用。
这是因为 Twitter 在回复时会自动提及您回复的用户。
有没有办法让它忽略回复,只听提及?
旧版 Twitter 流 API 在使用 track
关键字时不提供更复杂的查询,因此您必须在 tweeted 函数中自行过滤才能确定这是否是提及或回复/回复。
在新的 v2 过滤流中,您可以创建 rule that explicitly excludes replies to Tweets from the user. For example in your case you could have a rule of @ExampleName -is:reply
. At the moment, the twit
library does not support v2, but there are some alternatives, as well as sample code。
我正在开发一个 Twitter 机器人。一个主要特点是它需要在被提及时进行监听。我正在使用此代码执行此操作:
var stream = T.stream('statuses/filter', { track: @ExampleName });
stream.on('tweet', tweeted);
但是,当@ExampleName 的一条推文得到回复时,tweeted 函数仍然会被调用。
这是因为 Twitter 在回复时会自动提及您回复的用户。
有没有办法让它忽略回复,只听提及?
旧版 Twitter 流 API 在使用 track
关键字时不提供更复杂的查询,因此您必须在 tweeted 函数中自行过滤才能确定这是否是提及或回复/回复。
在新的 v2 过滤流中,您可以创建 rule that explicitly excludes replies to Tweets from the user. For example in your case you could have a rule of @ExampleName -is:reply
. At the moment, the twit
library does not support v2, but there are some alternatives, as well as sample code。