以简单的方式或工具在 Twitter(机器人)中自动回复推文?

发布于 2024-11-05 04:57:35 字数 117 浏览 0 评论 0 原文

是任何可能的&制作一个 Twitter 机器人的简单方法,它将在一定的时间间隔内回复一些推文(取决于搜索词)。谁能帮助我。

例如 twitter.com/shastribot

谢谢

is any possible & simple way to make a twitter bot that will reply to some tweets (depend on search terms) in certain time interval. can anyone help me.

for example twitter.com/shastribot

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

全部不再 2024-11-12 04:57:35

如果您喜欢 Ruby,那么我建议使用 Twitter gem:https://github.com/jnunemaker/twitter
它使事情变得非常容易。

然后,您可以编写一个脚本来检查是否有对机器人的任何回复,以及是否有任何新的回复发送消息。然后将其设置为 cron 作业,根据您认为需要的频率运行。

还有 Twitter 的 Twitter Bot 接口,我自己没有使用过,但可能值得一看:http:// /integrum.rubyforge.org/twitter_bot/

If you like Ruby, then I suggest using the Twitter gem: https://github.com/jnunemaker/twitter
It makes things very easy.

You could then write a script that checks whether there are any replies to the bot and if there are any new ones sends out a message. Then set it up as a cron job running as often as you think is necessary.

There's also the Twitter Bot interface to Twitter, I haven't used it myself but might be worth a look: http://integrum.rubyforge.org/twitter_bot/

挽袖吟 2024-11-12 04:57:35

您应该尝试 tweebot。它是 Twitter 机器人的 Python 微框架。该库提供了内置块(如过滤器、选择器和操作),您可以组合这些块来实现您的要求。例如,下一个代码演示了如何创建“retweet”机器人的规范实现(更多示例< /a>)。

# Next code demonstrates how to create simple twitter bot that select all
# friends' tweets with your mentiones and retweet they.

import tweebot as twb

def main():
    # Step 1. setup context configuration
    repeater = twb.Context({
        'app_name'        : 'repeater',
        'username'        : '<YOUR ACCOUNT NAME>',
        'consumer_key'    : '<YOUR CONSUMER KEY>',
        'consumer_secret' : '<YOUR CONSUMER SECRET>',
        'access_key'      : '<YOUR ACCESS KEY>',
        'access_secret'   : '<YOUR ACCESS SECRET>',
        'timeout'         : 10 * 60, # 10 min, ensure twitter api limits
        'history_file'    : 'history.json', # don't repeat answered tweets
    })

    # Step 2. enable pretty logging (stdout by default)
    twb.enable_logging(repeater)

    # Step 3. setup chain Selector->Filters->Action
    chain = (
        # Select recently tweets with current user mentions.
        twb.SearchMentions(),
        # Apply several filters to selected tweets:
        twb.MultiPart.And(
            # exclude answered, blocked and own tweets
            twb.BaseFilter,
            # then leave only friends tweets (friends list will be cached)
            twb.UsersFilter.Friends(),
            # and finally, exclude tweets with invalid content
            twb.BadTweetFilter),
        # And now, retweet remain tweets 
        twb.ReplyRetweet)

    # Step 4. start processing 
    repeater.start_forever(*chain)

if __name__ == '__main__':
    main()

You should try tweebot. It's python micro framework for twitter bots. This lib provides built-in blocks (like Filters, Selectors and Actions) that you can combine to achieve your requirements. For example, next code demonstrates how-to create canonical implementation of "retweet" bot (more examples).

# Next code demonstrates how to create simple twitter bot that select all
# friends' tweets with your mentiones and retweet they.

import tweebot as twb

def main():
    # Step 1. setup context configuration
    repeater = twb.Context({
        'app_name'        : 'repeater',
        'username'        : '<YOUR ACCOUNT NAME>',
        'consumer_key'    : '<YOUR CONSUMER KEY>',
        'consumer_secret' : '<YOUR CONSUMER SECRET>',
        'access_key'      : '<YOUR ACCESS KEY>',
        'access_secret'   : '<YOUR ACCESS SECRET>',
        'timeout'         : 10 * 60, # 10 min, ensure twitter api limits
        'history_file'    : 'history.json', # don't repeat answered tweets
    })

    # Step 2. enable pretty logging (stdout by default)
    twb.enable_logging(repeater)

    # Step 3. setup chain Selector->Filters->Action
    chain = (
        # Select recently tweets with current user mentions.
        twb.SearchMentions(),
        # Apply several filters to selected tweets:
        twb.MultiPart.And(
            # exclude answered, blocked and own tweets
            twb.BaseFilter,
            # then leave only friends tweets (friends list will be cached)
            twb.UsersFilter.Friends(),
            # and finally, exclude tweets with invalid content
            twb.BadTweetFilter),
        # And now, retweet remain tweets 
        twb.ReplyRetweet)

    # Step 4. start processing 
    repeater.start_forever(*chain)

if __name__ == '__main__':
    main()
偏闹i 2024-11-12 04:57:35

Ruby 的 twitter gem 是一个非常好的 gem。您可以使用 twitter API 查看可用的方法。

您可以从 Twitter::REST::Client 开始,如下所示:

twitter_client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

然后您可以将您的 twitter_client 用于各种目的。例如,您可以使用以下方式将推文发布到您的个人资料中:

twitter_client.update("I am posting this tweet from my Ruby program")

您可以通过提供 twitter 用户名来获取所有推文的列表,如下所示:

twitter_client.user_timeline("YOUR_TWITTER_USER_NAME").each do |tweet|
  puts tweet.text
end

要搜索推文,请查看

Ruby's twitter gem is a very good one. You can make use of twitter API to see the available methods.

You can start with a Twitter::REST::Client like following:

twitter_client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

Then you can you use your twitter_client for various purpose. For example you can post a tweet to your profile using this:

twitter_client.update("I am posting this tweet from my Ruby program")

You can get a list of all tweets by providing the twitter username like this:

twitter_client.user_timeline("YOUR_TWITTER_USER_NAME").each do |tweet|
  puts tweet.text
end

For searching for tweets, take a look at this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文