开发者

Ruby Twitter gem

-- UPDATE --

Ok its fixed. This is what I di开发者_如何学JAVAd. 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:inrequire' 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 ?


I believe it only works with Ruby 1.9 If you want to use twitter gem try version 0.9 with 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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜