views:

185

answers:

2

Any suggestions for a good twitter library (preferably in Ruby or Python)? I have a list of usernames, and I need to be able to programmatically follow these users.

  1. I tried twitter4r in Ruby, but finding users doesn't seem to work. When I do

    twitter = Twitter::Client.new(:login => 'mylogin', :password => 'mypassword')
    user = Twitter::User.find('ev', twitter)
    

...the user returned always seems to be some guy named "Jose Italo", no matter what username I try.

  1. Similary, I tried python-twitter, but following users doesn't seem to work. When I do

    api = twitter.Api(username='mylogin', password='mypassword')
    user = api.GetUser('ev')
    api.CreateFriendship(user)
    

...I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.5-i386/egg/twitter.py", line 1769, in CreateFriendship
  File "build/bdist.macosx-10.5-i386/egg/simplejson/__init__.py", line 307, in loads
  File "build/bdist.macosx-10.5-i386/egg/simplejson/decoder.py", line 335, in decode
  File "build/bdist.macosx-10.5-i386/egg/simplejson/decoder.py", line 353, in raw_decode
ValueError: No JSON object could be decoded

So any suggestions for a working library, or how to get twitter4r or python-twitter working?

+1  A: 

http://github.com/jnunemaker/twitter/ has been working pretty good for me.

Although, If I am just doing something simple, I usually resort to the bare HTTP API. In this case it would be this one: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-friendships%C2%A0create

Using Ruby with RestClient that would look something like this:

require "rest_client"
require "json"

r = RestClient.post "http://username:[email protected]/friendships/create.json",
        :screen_name => "user_to_follow"
j = JSON.parse(r)

And you have the response as a hash. Easy.

Harry Vangberg
Thanks, haven't tried out jnunemaker's library, but the bare HTTP API works great!
Ruld
A: 

whAT if i don't want to use ruby? I want to use python why is it so hard to find something that works for a simple search for users based upon keyword and mass follow?

InsiderAffiliates