ruby - How to get the number of unread tweets of a user using twitter gem in rails app -


im using twitter gem retrieve tweets. how unread tweets since last logged in ?

 def twitter     @twitter = twitter.user_timeline('pallavi_shastry', :count => 10)  end 

twitter api doesn't have such option user_timeline. but, since have store last login time anyway, can store last tweet id read , tweets ids higher that.

def twitter(username, last_tweet_id = nil)   # display latest 10 tweets if   # have never read user's timeline before   opts = last_tweet_id ? { :since_id => last_tweet_id } : { :count => 10 }    twitter.user_timeline(username, opts) end 

then can use method way:

# tweets newer 365677293978398720 @twitter = twitter('pallavi_shastry', 365677293978398720)  # 10 latest tweets @twitter = twitter('pallavi_shastry') 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -