回答
的API文檔指定狀態,這個調用將返回的最大數量爲200
https://dev.twitter.com/docs/api/1/get/statuses/user_timeline
指定鳴叫的次數嘗試和檢索,最多的200。計數的值最好被認爲是對要返回的推文數量的限制,因爲在應用計數後暫停或刪除的內容會被刪除。即使include_rts未提供,我們也會在轉發中包含轉推。建議您在使用此API方法時始終發送include_rts = 1。
這裏的東西我已經用了一個項目,必須做到這一點:
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密鑰。
謝謝你的迴應!這個代碼可以在android上使用嗎? – Sebastian 2013-03-10 13:43:30
我知道Android支持Python腳本:http://code.google.com/p/android-scripting/ – 2013-03-10 16:07:26
- 1. Twitter API獲取任何用戶的所有推文
- 2. XAML-Twitter客戶端。獲取來自用戶的所有推文
- 3. 獲取使用TweetSharpAPI的所有用戶的推文
- 4. 如何讓用戶使用twitter API獲取所有喜歡的推文?
- 5. 獲取Twitter用戶的所有推文,限速問題
- 6. 在特定日期後獲取用戶的所有推文
- 7. 如何使用LinqToTwitter獲取所有關於Hashtag的推文
- 8. 如何獲取用戶在戶外上傳的所有文檔
- 9. 從用戶家庭時間線上獲取所有以前的推文推特
- 10. 如何使用JavaScript從用戶賬戶獲取推文
- 11. 獲取所有帽子的所有推文
- 12. 如何從tweepy的twitter中獲得所有推特的推文
- 13. 獲取Twitter上GAE的所有推文的轉推量?
- 14. 獲取所有用戶的所有云端硬盤文件
- 15. 推特,獲取過去24小時內的所有推文
- 16. 如何從推文中提取screen_name並使用它來獲取該用戶的所有過去收藏夾?
- 17. 如何獲取本地用戶所屬的所有本地組
- 18. 如何獲取用戶所做的所有Twitter更新?
- 19. 如何獲取所有用戶文件夾Box API v2
- 20. 在單個查詢中獲取所有推薦用戶?
- 21. 獲取sharepoint 2010中的所有用戶配置文件用戶
- 22. Twitter API:如何從時間範圍獲取用戶的推文?
- 23. 如何獲取Twitter用戶社區的最新推文信息,
- 24. 如何在Android中獲取Twitter用戶的最新推文
- 25. 如何從任何用戶的推特獲得'n'推文
- 26. 從推文中獲取用戶名
- 27. Twitter:如何使用twitter api獲取json格式的所有推文
- 28. 獲取所有帶有特定標籤的推文
- 29. 如何使用node.js獲取推文
- 30. 如何使用AppleScript獲取推文
可以在Python/Ruby中執行此操作嗎? – 2013-03-07 16:34:15