简体   繁体   English

查找和添加Twitter用户?

[英]Finding and adding twitter users?

Any suggestions for a good twitter library (preferably in Ruby or Python)? 对于一个好的推特库(最好是Ruby或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. 我在Ruby中尝试了twitter4r,但找到用户似乎并不起作用。 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. ...用户返回似乎总是一个名叫“Jose Italo”的人,无论我尝试用什么用户名。

  1. Similary, I tried python-twitter, but following users doesn't seem to work. 同样,我尝试过python-twitter,但是用户似乎没有工作。 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? 那么对工作库的任何建议,或者如何让twitter4r或python-twitter工作?

http://github.com/jnunemaker/twitter/ has been working pretty good for me. http://github.com/jnunemaker/twitter/一直对我很好。

Although, If I am just doing something simple, I usually resort to the bare HTTP API. 虽然,如果我只是做一些简单的事情,我通常会使用裸HTTP API。 In this case it would be this one: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-friendships%C2%A0create 在这种情况下,它将是这一个: http//apiwiki.twitter.com/Twitter-REST-API-Method%3A-friendships%C2%A0create

Using Ruby with RestClient that would look something like this: 使用Ruby和RestClient看起来像这样:

require "rest_client"
require "json"

r = RestClient.post "http://username:password@twitter.com/friendships/create.json",
        :screen_name => "user_to_follow"
j = JSON.parse(r)

And you have the response as a hash. 并且您将响应作为哈希。 Easy. 简单。

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

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