[英]Find Twitter friends with Python
我創建了一個Twitter個人資料列表,我想下載他們的朋友(他們關注的用戶)。
我在Twitter開發人員上注冊,但是如果不對每個用戶進行身份驗證,就無法通過API進行注冊。
您是否知道其他方法可以讓我下載朋友列表而無需將每個用戶都放在列表中進行身份驗證?
嘗試使用流式API,Twitter並沒有像其關注者那樣真正擁有好友列表。 跟隨者不一定要考慮為朋友。 您想從個人資料開始,抓取每個關注者並獲取他們的關注者。
def extract_followers(user_id, limit):
cursor = -1
ids = []
while cursor != 0:
# Assume you have some method to make the twitter connection request where you can pass set of userIds)
response = twitter_connection(ids, cursor)
if response is not None:
ids += response['ids']
cursor = response['next_cursor']
print >> sys.stderr, 'Fetched %i total ids for %s' % (len(ids), user_id)
if len(ids) >= limit or response is None:
break
return ids
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.