Ruld
Ruld

Reputation:

Finding and adding twitter users?

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?

Upvotes: 3

Views: 446

Answers (1)

Harry Vangberg
Harry Vangberg

Reputation: 868

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.

Upvotes: 1

Related Questions