简体   繁体   中英

Ruby Twitter gem

-- UPDATE --

Ok its fixed. This is what I did. remove all ruby and rubygems completely. then install ruby1.9.1-full and rubygems1.9.1 then install the twitter gem.

Hi guys,

I am having trouble working with the Twitter gem. I am using ruby 1.8.7

After installing when I try to run a simple script I get this error

ruby twitter.rb ./twitter.rb:5: uninitialized constant Twitter (NameError) from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in require' from twitter.rb:2

I running this on a Ubuntu box. I checked with gem -list and I see the Twitter (1.1.0) is listed there.

this is the code I am trying to run

require "rubygems"
require 'twitter'


puts Twitter.user_timeline("test").first.text 

Any ideas ?

我相信它仅适用于Ruby 1.9如果要使用twitter gem,请尝试将0.9与Ruby 1.8.x一起使用

This works for me:

ruby-1.9.2-p0 > require 'twitter'
 => true 
ruby-1.9.2-p0 > puts Twitter.user_timeline("test").first.text 
TExES Pedagogy and Professional Responsibilities EC-12 Teacher Certification Test Prep Study Guid… - by Sharon A Wynne http://amzn.to/f3kF74
 => nil 

which version of ruby are you using?

gouravtiwari21's comment seems to fix the problem, but it's wrong to suggest that the twitter gem requires 0.9.0 if you want to run it using Ruby 1.8.x.

You can check out the version compatibility here: http://travis-ci.org/#!/jnunemaker/twitter

It shows the twitter gem working with Ruby installs as low as 1.8.7.

For me, it was an issue with having the correct dependent gems, as well as the correct versions.

Here's how I got it working:

I ran:

sudo gem list

And compared the versions of specific gems with what I found here: https://github.com/jnunemaker/twitter/blob/master/HISTORY.md (I simply searched for the word 'dependency' to see which versions twitter cared about.

I also found this diff: https://github.com/jnunemaker/twitter/commit/ac8114c1f6ba2da20c2267d3133252c2ffc6b6a3

And I compared the gems listed there with what I had installed, and I just made sure my system lined up with what I was seeing in the version notes. Oftentimes what happened is that I had multiple versions of a gem, and for some reason, the lower version was taking precedence.

I'm not sure why I still have to add

gem 'twitter', '1.7.1'

to my Gemfile, but alas, that's the last step required in order to get this stuff working.

Don't forget to restart your server, and you should be good!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM