Skip to content

Instantly share code, notes, and snippets.

@VanessaHenderson VanessaHenderson/readme.md
Last active Oct 25, 2017

Embed
What would you like to do?

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
@hellogerard

This comment has been minimized.

Copy link

hellogerard commented Jan 27, 2015

Nice widget. Got this error upon startup: undefined local variable or method 'mentions' for main:Object.

Managed to get this modified version working:

  begin
    timeline = twitter.mentions_timeline
    if timeline
      mentions = timeline.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
@robertolos

This comment has been minimized.

Copy link

robertolos commented Oct 1, 2015

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

This comment has been minimized.

Copy link

PeterBi87 commented Oct 15, 2015

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

This comment has been minimized.

Copy link

hostingnuggets commented Jul 24, 2017

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

This comment has been minimized.

Copy link

AntoineMOREL1 commented Oct 25, 2017

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
You can’t perform that action at this time.