简体   繁体   English

Ruby Twitter宝石

[英]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. 然后安装ruby1.9.1-full和rubygems1.9.1,然后安装twitter gem。

Hi guys, 嗨,大家好,

I am having trouble working with the Twitter gem. 我在使用Twitter gem时遇到麻烦。 I am using ruby 1.8.7 我正在使用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 ruby twitter.rb ./twitter.rb:5:来自/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:在/usr/lib/ruby/1.8/rubygems中的gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in未初始化常量Twitter(NameError) gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in require'来自twitter.rb:2

I running this on a Ubuntu box. 我在Ubuntu盒子上运行它。 I checked with gem -list and I see the Twitter (1.1.0) is listed there. 我检查了gem -list,发现其中列出了Twitter(1.1.0)。

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. gouravtiwari21的评论似乎可以解决此问题,但如果您想使用Ruby 1.8.x运行twitter gem,则它要求0.9.0是错误的。

You can check out the version compatibility here: http://travis-ci.org/#!/jnunemaker/twitter 您可以在此处查看版本兼容性: http : //travis-ci.org/#!/jnunemaker/twitter

It shows the twitter gem working with Ruby installs as low as 1.8.7. 该图显示了使用Ruby的Twitter gem最低安装为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. 并将特定宝石的版本与我在这里找到的内容进行比较: https : //github.com/jnunemaker/twitter/blob/master/HISTORY.md (我只是搜索“依赖”一词,以了解推特关心的版本。

I also found this diff: https://github.com/jnunemaker/twitter/commit/ac8114c1f6ba2da20c2267d3133252c2ffc6b6a3 我也发现了这个差异: 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. 然后,我将此处列出的gem与安装的宝石进行了比较,并确保系统与版本说明中的内容保持一致。 Oftentimes what happened is that I had multiple versions of a gem, and for some reason, the lower version was taking precedence. 通常,发生的事情是我有多个版本的gem,由于某种原因,较低版本的版本优先。

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. 到我的Gemfile,但是,las,这是使此材料正常工作所需要的最后一步。

Don't forget to restart your server, and you should be good! 不要忘记重启服务器,您应该会很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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