Skip to content

Instantly share code, notes, and snippets.

@jeroenbegyn
Last active September 11, 2021 19:28
Show Gist options
  • Save jeroenbegyn/5419267 to your computer and use it in GitHub Desktop.
Save jeroenbegyn/5419267 to your computer and use it in GitHub Desktop.
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
@OliPassey
Copy link

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
Copy link

herdir commented Sep 16, 2016

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

@sdkibb
Copy link

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