2013-02-12 105 views

回答

1

的API文档指定状态,这个调用将返回的最大数量为200

https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

指定鸣叫的次数尝试和检索,最多的200。计数的值最好被认为是对要返回的推文数量的限制,因为在应用计数后暂停或删除的内容会被删除。即使include_rts未提供,我们也会在转发中​​包含转推。建议您在使用此API方法时始终发送include_rts = 1。

0

这里的东西我已经用了一个项目,必须做到这一点:

import json 
import commands 

import time 

def get_followers(screen_name): 

    followers_list = [] 

    # start cursor at -1 
    next_cursor = -1 

    print("Getting list of followers for user '%s' from Twitter API..." % screen_name) 

    while next_cursor: 

     cmd = 'twurl "/1.1/followers/ids.json?cursor=' + str(next_cursor) + \ 
       '&screen_name=' + screen_name + '"' 

     (status, output) = commands.getstatusoutput(cmd) 

     # convert json object to dictionary and ensure there are no errors 
     try: 
      data = json.loads(output) 

      if data.get("errors"): 

       # if we get an inactive account, write error message 
       if data.get('errors')[0]['message'] in ("Sorry, that page does not exist", 
                 "User has been suspended"): 

        print("Skipping account %s. It doesn't seem to exist" % screen_name) 
        break 

       elif data.get('errors')[0]['message'] == "Rate limit exceeded": 
        print("\t*** Rate limit exceeded ... waiting 2 minutes ***") 
        time.sleep(120) 
        continue 

       # otherwise, raise an exception with the error 
       else: 

        raise Exception("The Twitter call returned errors: %s" 
            % data.get('errors')[0]['message']) 

      if data.get('ids'): 
       print("\t\tFound %s followers for user '%s'" % (len(data['ids']), screen_name)) 
       followers_list += data['ids'] 

      if data.get('next_cursor'): 
       next_cursor = data['next_cursor'] 
      else: 
       break 

     except ValueError: 
      print("\t****No output - Retrying \t\t%s ****" % output) 

    return followers_list 



screen_name = 'AshwinBalamohan' 
followers = get_followers(screen_name) 
print("\n\nThe followers for user '%s' are:\n%s" % followers) 

为了得到这个工作,你需要安装红宝石宝石“Twurl”,这可在这里:https://github.com/marcel/twurl

我发现Twurl比其他Python Twitter包装更容易工作,所以选择从Python调用它。让我知道你是否希望我引导你如何安装Twurl和Twitter API密钥。

+0

谢谢你的回应!这个代码可以在android上使用吗? – Sebastian 2013-03-10 13:43:30

+0

我知道Android支持Python脚本:http://code.google.com/p/android-scripting/ – 2013-03-10 16:07:26

相关问题