Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Twitter Search with API v1.1

Description

Simple Dashing widget (and associated job) to display a Twitter search. Uses Twitter API v1.1.

##Dependencies

twitter

Add it to dashing's gemfile:

gem 'twitter'

and run bundle install. Everything should work now :)

##Usage

Put the twitter-search.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="twitter_mentions" data-view="Comments" data-title="Search Tweets" style="background-color: #71388a"></div>
</li>

##Settings

You'll need to add the twitter configs for your desired account to the job.

Tweets are fetched every 10 minutes, but you can change that by editing the job schedule.

require 'twitter'
Twitter.configure do |config|
config.consumer_key = 'YOUR_CONSUMER_KEY'
config.consumer_secret = 'YOUR_CONSUMER_SECRET'
config.oauth_token = 'YOUR_OAUTH_TOKEN'
config.oauth_token_secret = 'YOUR_OAUTH_TOKEN_SECRET'
end
search_term = URI::encode('#todayilearned')
SCHEDULER.every '10m', :first_in => 0 do |job|
tweets = Twitter.search("#{search_term}").results
if tweets
tweets.map! do |tweet|
{ name: tweet.user.name, body: tweet.text, avatar: tweet.user.profile_image_url_https }
end
send_event('twitter_mentions', comments: tweets)
end
end
@allisonmin

This comment has been minimized.

Show comment
Hide comment
@allisonmin

allisonmin Jul 9, 2013

I've followed your directions but nothing is being pulled into the widget when I start the dashboard. Was there anything else I needed to add?

I've followed your directions but nothing is being pulled into the widget when I start the dashboard. Was there anything else I needed to add?

@YoDK

This comment has been minimized.

Show comment
Hide comment
@YoDK

YoDK Jul 17, 2013

@allisonmin did you gem install twitter ?

YoDK commented Jul 17, 2013

@allisonmin did you gem install twitter ?

@gordhawkins

This comment has been minimized.

Show comment
Hide comment
@gordhawkins

gordhawkins Jul 19, 2013

I'm getting a weird SSL error whenever I launch dashing.. suspect it is coming from the twitter gem.

"SSL_connect SYSCALL returned=5 errno=0 state=unknown state"

Could be coming from the fact that I'm using this behind a crappy proxy that has a tendency to mangle SSL...

Any ideas?

I'm getting a weird SSL error whenever I launch dashing.. suspect it is coming from the twitter gem.

"SSL_connect SYSCALL returned=5 errno=0 state=unknown state"

Could be coming from the fact that I'm using this behind a crappy proxy that has a tendency to mangle SSL...

Any ideas?

@willwhitney

This comment has been minimized.

Show comment
Hide comment
@willwhitney

willwhitney Sep 6, 2013

The issue seems to be some kind of jank around Twitter's endpoint/gem. If you throw a OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE in the top of the file, everything works fine.

The issue seems to be some kind of jank around Twitter's endpoint/gem. If you throw a OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE in the top of the file, everything works fine.

@zimbatm

This comment has been minimized.

Show comment
Hide comment
@zimbatm

zimbatm Nov 21, 2013

The right solution is to bundle the cacert.pem, not to disable SSL...

Here is an update version of the gist with support for the twitter gem v5.0.0 and a fix for SSL: https://gist.github.com/zimbatm/7573436

zimbatm commented Nov 21, 2013

The right solution is to bundle the cacert.pem, not to disable SSL...

Here is an update version of the gist with support for the twitter gem v5.0.0 and a fix for SSL: https://gist.github.com/zimbatm/7573436

@TimSmith714

This comment has been minimized.

Show comment
Hide comment
@TimSmith714

TimSmith714 Dec 18, 2013

Don't know if this solves your problem @allisonmin but I got "undefined" when I ran the widget searching for @pittisea because no one had retweeted or @'d us. I retweeted a tweet from my personal account and that showed in the widget.
I removed the @ and the search started showing our tweets as well.

Don't know if this solves your problem @allisonmin but I got "undefined" when I ran the widget searching for @pittisea because no one had retweeted or @'d us. I retweeted a tweet from my personal account and that showed in the widget.
I removed the @ and the search started showing our tweets as well.

@paulbz

This comment has been minimized.

Show comment
Hide comment
@paulbz

paulbz Mar 13, 2014

Hi everyone, working well for me but images aren't being shown. Do you know how we can get images to appear?

paulbz commented Mar 13, 2014

Hi everyone, working well for me but images aren't being shown. Do you know how we can get images to appear?

@arvindsankaran

This comment has been minimized.

Show comment
Hide comment
@arvindsankaran

arvindsankaran Sep 12, 2014

First of all thanks jeroenbegyn for sharing this script. It works great for me.

I also wanted to display the time of the tweet and was able to get this from 'tweet.created_at' in the .rb file but didn't know the exact steps to display this within the dashing dashboard (.erb file).
Can someone kindly suggest the exact solution for this please?

Thanks

First of all thanks jeroenbegyn for sharing this script. It works great for me.

I also wanted to display the time of the tweet and was able to get this from 'tweet.created_at' in the .rb file but didn't know the exact steps to display this within the dashing dashboard (.erb file).
Can someone kindly suggest the exact solution for this please?

Thanks

@Cornellio

This comment has been minimized.

Show comment
Hide comment
@Cornellio

Cornellio Jan 28, 2015

Works perfectly for me. Thank you for sharing this information.

Works perfectly for me. Thank you for sharing this information.

@sansepic

This comment has been minimized.

Show comment
Hide comment
@sansepic

sansepic Apr 27, 2015

Works well for me but I can't figure out how to change the search topic. Currently it only finds #todayilearned. I tried changing this to line in the "twitter.rb" file but I still get the same twitter stuff.
search_term = URI::encode('#bettercallsaul'))
TIA.

Works well for me but I can't figure out how to change the search topic. Currently it only finds #todayilearned. I tried changing this to line in the "twitter.rb" file but I still get the same twitter stuff.
search_term = URI::encode('#bettercallsaul'))
TIA.

@mkaag

This comment has been minimized.

Show comment
Hide comment
@mkaag

mkaag Jun 29, 2015

Hi @paulbz, it appears that the content of tweet.user.profile_image_url_https has changed and does now contains more data. I have modified the script like that:

avatar: tweet.user.profile_image_url_https.scheme + "://" + tweet.user.profile_image_url_https.host + tweet.user.profile_image_url_https.path

Hope it helps.

mkaag commented Jun 29, 2015

Hi @paulbz, it appears that the content of tweet.user.profile_image_url_https has changed and does now contains more data. I have modified the script like that:

avatar: tweet.user.profile_image_url_https.scheme + "://" + tweet.user.profile_image_url_https.host + tweet.user.profile_image_url_https.path

Hope it helps.

@OliPassey

This comment has been minimized.

Show comment
Hide comment
@OliPassey

OliPassey Oct 28, 2015

Has something changed recently?
Was originally getting Cannot authenticate errors on the Twitter Widget that came with dashing, switched to your version. now getting this error:

twitter-search.rb:3:in <top (required)>': undefined methodconfigure' for Twitter:Module (NoMethodError)

And dashing fails to start - any ideas?

Has something changed recently?
Was originally getting Cannot authenticate errors on the Twitter Widget that came with dashing, switched to your version. now getting this error:

twitter-search.rb:3:in <top (required)>': undefined methodconfigure' for Twitter:Module (NoMethodError)

And dashing fails to start - any ideas?

@herdir

This comment has been minimized.

Show comment
Hide comment
@herdir

herdir Sep 16, 2016

I've the same problem as @OliPassey and can't find where it come from

herdir commented Sep 16, 2016

I've the same problem as @OliPassey and can't find where it come from

@sdkibb

This comment has been minimized.

Show comment
Hide comment
@sdkibb

sdkibb Mar 1, 2017

gem 'twitter' doesn't work. Is this project outdated and not functional or did it ever work?

sdkibb commented Mar 1, 2017

gem 'twitter' doesn't work. Is this project outdated and not functional or did it ever work?

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