2013-02-12 106 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

相關問題