I'm trying to bring my latest status from Twitter to my Rails app. I have the config details stored in an initialiser and have it displaying my latest tweet, but I want to also bring the date of this tweet. I have the following code and not sure whether to try and amend it or start again.
initializers.twitter.rb
module TwitterStatus
$client = Twitter::REST::Client.new do |config|
config.consumer_key = "##hidden##"
config.consumer_secret = "##hidden##"
config.access_token = "##hidden##"
config.access_token_secret = "##hidden##"
end
def user_timeline(qt)
$client.user_timeline(count: qt)
end
end
controllers/application_contorller.rb
include TwitterStatus
def index
@tweets = user_timeline(1)
end
main/index.html.erb
<% @tweets.each do |tweet| %>
<p><%= link_to tweet.text, "https://www.twitter.com/#{tweet.user.screen_name}" %></p>
<% end %>
Any help would be appreciated, ideally, I'd like to be able to pull all the tweet info (img, name, etc...) and just use what I need.
Aucun commentaire:
Enregistrer un commentaire