Skip to content

Instantly share code, notes, and snippets.

@VanessaHenderson
Last active December 8, 2022 08:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VanessaHenderson/9aa0823efdfc085f675d to your computer and use it in GitHub Desktop.
Save VanessaHenderson/9aa0823efdfc085f675d to your computer and use it in GitHub Desktop.

Another Twitter widget is rolling your way! This widget will scroll through the most recent tweets that mention the account associated with the keys! To get this widget up and running you only need to add your keys into this area of twitter.rb:

 config.consumer_key = 'YOUR_CONSUMER_KEY'
 config.consumer_secret = 'YOUR_CONSUMER_SECRET_KEY'
 config.access_token = 'YOUR_ACCESS_TOKEN'
 config.access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET'

If you haven't got your keys yet, head over to https://dev.twitter.com/docs/auth/tokens-devtwittercom and grab them there.

To display the mentions, the comments widget provided with dashing was used. This is what you need in your dashboard .erb file to make them work. The widget also inserts the twitter bird logo behind the widget for astetics.

  <li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
      <div data-id="twitter_mentions" data-view="Comments" style="background-color:#00afd7;" data-moreinfo="Tweets @sourceclear" ></div>
      <i class="icon-twitter icon-background"></i>
  </li>
require 'twitter'
#### Get your twitter keys & secrets:
#### https://dev.twitter.com/docs/auth/tokens-devtwittercom
twitter = Twitter::REST::Client.new do |config|
config.consumer_key = 'YOUR_CONSUMER_KEY'
config.consumer_secret = 'YOUR_CONSUMER_SECRET_KEY'
config.access_token = 'YOUR_ACCESS_TOKEN'
config.access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET'
end
SCHEDULER.every '15m', :first_in => 0 do |job|
begin
user = twitter.user
if mentions
mentions = mentions.map do |tweet|
{ name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https }
end
send_event('twitter_mentions', {comments: mentions})
end
rescue Twitter::Error
puts "\e[33mThere was an error with Twitter\e[0m"
end
end
@robertolos
Copy link

The avatar is not working. Managed to get it working with the folliwing change:
{ name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https.to_s }

@PeterBi87
Copy link

I followed the insctructions and changed the things mentioned above.

But i always get an "undefined" in the widget. There's no error in the terminal. The dashboard works, the twitter-icon is there, but the text is only "undefined".

Any ideas?

@hostingnuggets
Copy link

Nice widget! I have one question: how can I change the rotation speed of the tweets being displayed? it seems to be by default around 10 seconds.

@AntoineMOREL1
Copy link

Despite hellogerard's instructions, i have the same problem as PeterBi87.
The dashboard works but the widget shows "undefined".

Can somebody help ?

Thks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment