Reply to tweets on your timeline using Twitter

I am trying to create a simple answer from my timeline, but ran into some problems, and as a newbie to Ruby, I had problems understanding the document.

Twitter.mentions_timeline.each do |tweet| reply_to = tweet.from_user_name() #Twitter.update("@#{reply_to} Not today.") end 

This is what has been written so far, that little. Unfortunately, the tweet does not have the name from_user_name when using the mentions_timeline link. I use this stone and cannot find any good examples of this: https://github.com/sferik/twitter

It would be nice to have a good example of how to capture tweets from the timeline and respond to them. Is there also a twitter that distinguishes β€œnew tweets” or do I need to create some kind of storage to separate the new from the old?

Thanks in advance:)

EDIT: to clarify, I want all tweets to be sent directly to me and answered them. I really do not want to continue the conversation.

+7
ruby twitter
source share
2 answers

A bit late, but in the latest twitter gem version you can reply to a tweet with:

@client.update("@#{reply_to.user.username} Not today.", in_reply_to_status_id: reply_to.id)

Hope this helps someone.

+5
source share

Here are a few examples that might be useful for anyone using sferik twitter gem for something like this. Note that I am currently using version 5.0.0, so your mileage may vary.

Assuming you set up a REST client and assign it a variable called client , you can get an array from your last 20 references (or no matter how much you received in the last 2 months, if less), this line:

 client.mentions_timeline.map(&:full_text) 

Relevant references to these tweets can be obtained in a similar way:

 client.mentions_timeline.map(&:user).map(&:username) 

Then you can use client.update as prompted to answer as you like.

One tool that I find incredibly useful when I learn the APIs in Ruby, pry . Just require , release binding.pry and run your code in the terminal. Then you can explore your heart - or an API limitation.

0
source share

All Articles