I'm using a recent version of Tweetstream and can't seem to connect to the twitter streaming API. I'm authenticating through oAuth like so:
require "rubygems"
require "tweetstream"
def index
TweetStream.configure do |config|
config.consumer_key = 'aaa'
config.consumer_secret = 'aaa'
config.oauth_token = '11329872-aaa'
config.oauth_token_secret = 'aaa'
config.auth_method = :oauth
config.parser = :yajl
end
TweetStream::Client.new.track('words') do |status|
puts "streaming"
puts "#{status.text}"
end
end
It eventually times out though with the following:
TweetStream::ReconnectError (Failed to reconnect after 7 tries.)
Any idea what's wrong?
Found the solution to this one was a missing required gem. All I needed to add was:
require 'yajl'
I also noticed that this is only required if you're using oAuth to authenticate with twitter.
Related
I'm having issues trying to experiment with the twitter gem. My rails app is pretty simple. No devise or authentication at the moment. I'm more interesting in just making API calls and collect batch data to experiment with D3 at a later point.
I'm trying to follow the vague documentation and this is as far as I got.
# config/initializers/twitter_client.rb
require 'twitter'
twitter = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['##############']
config.consumer_secret = ENV['##############']
config.access_token = ENV['##############']
config.access_token_secret = ENV['##############']
end
So now I want to byebug during an action in order to poke around. However, the controller doesn't seem to understand the twitter variable. I've tried making them instance and global. I am probably failing to require something. But, I was under the impression initializer files are accessable everywhere by default.
If you want global variable. Use :: operator
# config/initializers/twitter_client.rb
require 'twitter'
::MyTwitter = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['##############']
config.consumer_secret = ENV['##############']
config.access_token = ENV['##############']
config.access_token_secret = ENV['##############']
end
Then you will be able to use MyTwitter anywhere in your app.
I'm trying to display tweets using gem tweetstream and following the guide at https://github.com/tweetstream/tweetstream
In my tweets_helper.rb
require "twitter" require 'tweetstream'
module TweetsHelper
##client = Twitter::REST::Client.new do |config|
config.consumer_key = Rails.application.config.twitter_key
config.consumer_secret = Rails.application.config.twitter_secret
config.access_token = Rails.application.config.twitter_oauth_token
config.access_token_secret = Rails.application.config.twitter_oauth_secret
end
def user_timeline
##client.user_timeline
end
TweetStream.configure do |config|
config.consumer_key = Rails.application.config.twitter_key
config.consumer_secret = Rails.application.config.twitter_secret
config.oauth_token = Rails.application.config.twitter_oauth_token
config.oauth_token_secret = Rails.application.config.twitter_oauth_secret
config.auth_method= :oauth
end
TweetStream::Client.new.track('Pink Floyd') do |status|
puts "#{status.text}"
end
end
But this throws me this error in the terminal and shuts down the localserver
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/tweetstream-2.6.1/lib/tweet
stream/client.rb:400: warning: epoll is not supported on this platform
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/tweetstream-2.6.1/lib/tweet
stream/client.rb:401: warning: kqueue is not supported on this
platform terminate called after throwing an instance of
'std::runtime_error' what(): Encryption not available on this
event-machine
This application has requested the Runtime to terminate it in an
unusual way. Please contact the application's support team for more
information.
However the server runs if I remove
TweetStream::Client.new.track('Pink Floyd') do |status|
puts "#{status.text}"
end
How do I fix this error?
UPDATE
I think all signs point to installing libssl-dev https://github.com/plamoni/SiriProxy/issues/41. On Ubuntu it is aptitude install libssl-dev.
How do I do it on windows 8?
I've been trying to get the Twitter Gem running. I followed the documentation and placed
client = Twitter::REST::Client.new do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consumer_secret = "YOUR_CONSUMER_SECRET"
config.access_token = "YOUR_ACCESS_TOKEN"
config.access_token_secret = "YOUR_ACCESS_SECRET"
end
I placed it in a custom initializer file called Twitter.rb
When I try to run rails console it gives me this error " uninitialized constant Twitter::REST (NameError)"
This error was reported here
The solution is to use Twitter::Client.new (no ::REST)
I faced with same issue. But I have installed two gems https://github.com/sferik/twitter and https://github.com/twitter/twitter-text-rb, they both have 'Twitter' as main module and when I call Twitter, I reached second instead first...
Twitter::Client.new - not working to.
add require 'twitter' on the top of your file
I don't like asking noobie questions but I've spent more time than I care to admit googling and trying to figure out this simple process. I'm trying to use the twitter gem to post tweets in my app's views.
I have this script that works when I run it on the command line, but I don't know how to access the data on my views. I have the gem installed. I tried adding this code to my controller but it still doesn't let me call it in the view.
require 'rubygems'
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "(redacted)"
config.consumer_secret = "(redacted)"
config.access_token = "(redacted)"
config.access_token_secret = "(redacted)"
end
client.search("help", :result_type => "recent").take(3).each do |tweet|
puts tweet.text
end
If anyone can point me in the right direction, that would be great.
Well, I'll post some (untested) code that might help set you in the right direction. It's not the best way to do it, as it's not very flexible, but it should do what your example does. Make sure add the Twitter gem to your Gemfile and bundle install. Create a Ruby class called TweetsFromAccount. Saving it in the /lib directory works just fine.
class TweetsFromAccount
def initialize
#client = Twitter::REST::Client.new do |config|
config.consumer_key = "(redacted)"
config.consumer_secret = "(redacted)"
config.access_token = "(redacted)"
config.access_token_secret = "(redacted)"
end
end
def recent_tweets(quantity)
array_of_tweets = []
#client.search("help", :result_type => "recent").take(quantity).each do |tweet|
array_of_tweets << tweet.text
end
end
end
In the controller, create a new TweetsFromAccount object and assign it to an instance variable, #tweets. Create an additional instance variable set the value of #tweets.recent_tweets(3). This should fetch the 3 most recent tweets.
def show
# other stuff
#tweets = TweetsFromAccount.new
#array_of_tweets = #tweets.recent_tweets(3)
end
Then in your view, just iterate over #array_of_tweets.
<ul>
<% #array_of_tweets.each do |tweet| %>
<li><%= tweet %></li>
<% end %>
</ul>
I am new to Ruby on Rails as i want to develop a twitter app with the search option. Using which an user can search for the other users. I am using twitter gem and oauth gem for my project. I Have tried using below given code but its not working though get_client.search("user") it working in Rails Console.
def get_client
Twitter::REST::Client.new do |config|
config.consumer_key = "ABCD"
config.consumer_secret = "XYZ"
config.access_token = "PQRS"
config.access_token_secret = "LMNO"
end
end
def search
query = (param[:search])
get_client.search("query")
end