I am trying to create a simple reply from my twitter timeline but ran into some problems and as a ruby newbie I had problems in understanding the doc.
Twitter.mentions_timeline.each do |tweet|
reply_to = tweet.from_user_name()
#Twitter.update("@#{reply_to} Not today.")
end
This is what've written so far, which is not much. Unfortunately the tweet doesn't have any from_user_name when using the mentions_timeline it seems. I am using this gem and does not find any good examples of this: https://github.com/sferik/twitter
Would be very nice to have some nice example of how to grab ones tweets from the timeline and replying to those. Also does twitter have anything that distinguish "new tweets" or do I need to create some kind of storage myself to seperate new from old?
Thanks in advance :)
EDIT: to clarify, I want to get all tweets sent to me directly and reply to them. I don't really want to continue in any conversation.
The algorithm considers several variables, such as the people you follow, your retweets and liked tweets, the popularity of the tweets, geography, timeframes, and tweet engagement. Consequently, when you log onto Twitter, you will see tweets that the algorithm thinks you'll be most interested in.
A little late, but in the lastest version of twitter gem
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.
Here are a few examples that might be helpful for anyone using sferik's twitter gem for something like this. Note, I'm using version 5.0.0 currently, so your mileage may vary.
Assuming you've configured the REST client and assigned it to a variable named client
, you can get an array of your last 20 mentions (or however many you've received in the past 2 months, if fewer) with this line:
client.mentions_timeline.map(&:full_text)
The respective mentioners of those tweets can be acquired similarly with this:
client.mentions_timeline.map(&:user).map(&:username)
You could then use client.update
as suggested to reply as you see fit.
One tool I find incredibly useful when I'm exploring API's in Ruby is pry
. Just require
it, drop a binding.pry
, and run your code in Terminal. Then you can explore to your heart's — or API's limit's — extent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With