SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question twitter ruby gem not working

    hi guys,

    new to ruby and rails. read a good chunk of simply rails 2 and i want to play around with the twitter api. instead of parsing it all myself i saw there was a twitter ruby gem on rubyforge

    i'm on ubuntu linux. i ran
    sudo gem install twitter
    and
    sudo install twitter

    when i run the code:
    Code:
    require 'rubygems'
    require 'twitter'
    
    #searches all tweets for httparty
    Twitter::Search.new('httparty').each { |r| puts r.inspect }
    i get the error:
    ./twitter.rb:5: uninitialized constant Twitter (NameError)
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    from -:2

    any idea of what i'm doing wrong? thanks!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Hi stevekl, welcome to the forums,

    If you do "$ gem list", is twitter there?

  3. #3
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey,

    twitter is listed there. any insight?

    thanks!

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I haven't installed the twitter gem to try it, but I did download it and take a quick look. Several of the files in the examples folder start with
    Code Ruby:
    require 'rubygems'
    require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
    config = YAML::load(open(ENV['HOME'] + '/.twitter'))
     
    twitter = Twitter::Base.new(config['email'], config['password'])
    But your code
    Code Ruby:
    require 'rubygems'
    require 'twitter'
     
    #searches all tweets for httparty
    Twitter::Search.new('httparty').each { |r| puts r.inspect }
    looks similar to
    search.rb
    Code Ruby:
    require 'rubygems'
    require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
     
    Twitter::Search.new('httparty').each { |r| puts r.inspect,'' }
    .....
    Are you sure your path to "twitter" is correct?

  5. #5
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it seems like my path to twitter is correct, because it's not throwing an error on the require line. while if i put require 'twitter-fake' or something that doesnt exist an error is thrown. but, also i can't be positive because i don't know where the ruby gem installer installs the twitter lib.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I have Windows OS, my "plugin" gems are in the ["my app"]\vendor\plugins\ folder. The Ruby gems are in ["ruby install dir"]\lib\ruby\gems\1.8\gems\

  7. #7
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your help so far

    so i found it's located at: usr/lib/ruby/gems/1.8/gems/twitter-0.3.7/
    still not sure how to get this working though.

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I'll install the gem (it may take a while) to see if I can get it to work and post back.

  9. #9
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that'd be great..thanks so much

  10. #10
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I didn't try any code yet. But I did finally finish installing (darn bulk update arrgghh). There were a few dependencies, did you get them too?
    Code:
    C:\ruby>gem install twitter --version 0.3.7
    Bulk updating Gem source index for: http://gems.rubyforge.org
    Install required dependency main? [Yn]  y
    Install required dependency fattr? [Yn]  y
    Install required dependency arrayfields? [Yn]  y
    Install required dependency highline? [Yn]  y
    Install required dependency httparty? [Yn]  y
    When you HTTParty, you must party hard!
    Successfully installed twitter-0.3.7
    Successfully installed main-2.8.2
    Successfully installed fattr-1.0.3
    Successfully installed arrayfields-4.6.0
    Successfully installed highline-1.4.0
    Successfully installed httparty-0.1.3
    Installing ri documentation for twitter-0.3.7...
    Installing ri documentation for highline-1.4.0...
    Installing ri documentation for httparty-0.1.3...
    Installing RDoc documentation for twitter-0.3.7...
    Installing RDoc documentation for highline-1.4.0...
    Installing RDoc documentation for httparty-0.1.3...

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Without modifying any files or using any configuration info (vanilla install), I ran the search.rb file in the console
    Code:
    >ruby lib\ruby\gems\1.8\gems\twitter-0.3.7\examples\search.rb
    and got
    Code:
    .......
    
    {"text"=>"It's an HTTParty and everyone is invited!", "from_user"=>"freezingkiwi
    s", "to_user_id"=>nil, "id"=>930002532, "iso_language_code"=>"en", "from_user_id
    "=>577069, "created_at"=>"Mon, 22 Sep 2008 03:41:18 +0000", "profile_image_url"=
    >"http://s3.amazonaws.com/twitter_production/profile_images/55870740/n598981757_
    609237_5561_normal.jpg"}
    
    {"text"=>"wow, #HTTParty looks ****ing kickass. http://ping.fm/L8yjW", "from_use
    r"=>"Oshuma", "to_user_id"=>nil, "id"=>928353748, "iso_language_code"=>"en", "fr
    om_user_id"=>179003, "created_at"=>"Sat, 20 Sep 2008 13:06:21 +0000", "profile_i
    mage_url"=>"http://s3.amazonaws.com/twitter_production/profile_images/55598971/P
    hoto_24_normal.jpg"}
    
    {"text"=>"Here another  HTTParty test:  I'm posting via Rails script/console", "
    from_user"=>"lgswitter", "to_user_id"=>nil, "id"=>920995162, "iso_language_code"
    =>"en", "from_user_id"=>1594282, "created_at"=>"Sun, 14 Sep 2008 12:43:25 +0000"
    , "profile_image_url"=>"http://s3.amazonaws.com/twitter_production/profile_image
    s/54745327/luca_normal.jpg"}
    
    {"text"=>"It's an HTTParty test: automated messages via http://github.com/jnunem
    aker/httparty/tree/master Ruby lib", "from_user"=>"lgswitter", "to_user_id"=>nil
    , "id"=>919315278, "iso_language_code"=>"en", "from_user_id"=>1594282, "created_
    at"=>"Fri, 12 Sep 2008 19:29:46 +0000", "profile_image_url"=>"http://s3.amazonaw
    s.com/twitter_production/profile_images/54745327/luca_normal.jpg"}
    
    {"text"=>"@mibly did you play much with tagthe.net? i've done my opencalais trai
    ls... (httparty did it all for me there)", "from_user"=>"degsy", "to_user"=>"mib
    ly", "to_user_id"=>157426, "id"=>914336607, "iso_language_code"=>"en", "from_use
    r_id"=>164367, "created_at"=>"Mon, 08 Sep 2008 21:42:46 +0000", "profile_image_u
    rl"=>"http://s3.amazonaws.com/twitter_production/profile_images/56185617/degsy_n
    ormal.jpg"}
    
    {"text"=>"So much for getting my HTTParty on tonight. Submitted a LH ticket and
    moving on to play some SNES ROMs before sleeptime", "from_user"=>"robbyrussell",
     "to_user_id"=>nil, "id"=>906433948, "iso_language_code"=>"en", "from_user_id"=>
    9366, "created_at"=>"Tue, 02 Sep 2008 04:07:07 +0000", "profile_image_url"=>"htt
    p://s3.amazonaws.com/twitter_production/profile_images/58385383/robby_planetargo
    n.com_7be6dec6_normal.jpg"}
    
    {"text"=>"Happy that my trivial patches to HTTParty were just accepted. Now back
     to the pair programming.", "from_user"=>"wesm", "to_user_id"=>nil, "id"=>900980
    411, "iso_language_code"=>"en", "from_user_id"=>387286, "created_at"=>"Wed, 27 A
    ug 2008 21:57:19 +0000", "profile_image_url"=>"http://s3.amazonaws.com/twitter_p
    roduction/profile_images/14883442/wes-vanity_normal.png"}

  12. #12
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague,

    I've installed the twitter gem on my new acer aspire one netbook (what a sexy little machine she is...) and our search.rb code works fine. So, it's got to be some issue (dependency maybe, will investigate later) on the other machine. Now that I know it's machine specific I'll be able to investigate further when I have the time.

    Thanks again for all your help!

  13. #13
    SitePoint Enthusiast TomK32's Avatar
    Join Date
    Mar 2008
    Location
    Berchtesgaden, Germany
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to solve that tricky thing which I ran into myself, it works if you do like this:

    Code:
    require 'rubygems'
    require 'httparty'
    require 'mash'
    require 'twitter'
    require 'twitter/search'
    I'll have a talk with the gem's programmer how to fix that situation.
    just a geek trying to change the world
    I'm a ruby on rails developer in Vienna, Austria. My github.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •