2

I've tried using the gem twitter, grackle, and TweetStream but I can't figure out how to get a stream of a users @mentions.

I just can't figure out how to put together a bit of code that says 'get all mentions to user'. (and I want to tap into the @mention, not just search twitter for a username)

I'm using Sinatra :: I've got it all up and running :: I can post to a feed, pull specific status's and so on. Getting @mentions is eluding me.

alexbooots
  • 383
  • 6
  • 22
  • Perhaps the GET statuses/mentions page on dev.twitter will be of help: https://dev.twitter.com/docs/api/1/get/statuses/mentions – Melanie Palen Feb 11 '20 at 20:40

2 Answers2

2

I only use the oauth gem but this is how you can do it. Since you can post feed, I guess you have the process till the access_token.

>> response = access_token.get('http://api.twitter.com/1/statuses/mentions.json')
>> JSON.parse(response.body)
#=> Array of Hashes with all the info

By the way, I see a function already included in the Twitter gem source code.

tweet.rb

# @note Must include entities in your request for this method to work
# @return [Array<Twitter::Entity::UserMention>]
def user_mentions
  @user_mentions ||= entities(Twitter::Entity::UserMention, :user_mentions)
end
oldergod
  • 15,033
  • 7
  • 62
  • 88
0

You can use the search/tweets API from Twitter and set q: "@USERNAME" which will find the tweets that mention your user.

nathanchere
  • 8,008
  • 15
  • 65
  • 86
Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84