【问题标题】:Grabbing a users followers with Twython使用 Twython 吸引用户关注者
【发布时间】:2015-05-19 09:17:14
【问题描述】:

我有获取特定用户关注者的代码,如下所示。我想做的不仅仅是抓住用户的追随者,还要抓住追随者自己的追随者。一个例子是获取 Carl Icahn 的追随者 ID,然后让这些追随者拥有自己的追随者 ID。因此,如果我关注 Carl Icahn,我也将能够检索我所有的追随者。此外,出于某种原因,我每次通话都获得相同的 5000 个关注者,而不是每次都获得不同的 5000 个关注者。谁能帮我解决这个问题?我将不胜感激。

import logging
import time
import csv
import twython
import json

app_key = "**********"
app_secret = "**********"
oauth_token = "***********"
oauth_token_secret = "**************"

twitter = twython.Twython(app_key, app_secret, oauth_token, oauth_token_secret)

followers = twitter.get_followers_ids(screen_name = "Carl_C_Icahn")

for follower_id in followers:
    print ("Carl Icahn followers:", followers)

    with open('carlfollowers.txt', 'a') as outfile:
         json.dump(followers, outfile, sort_keys = True, indent = 4)

【问题讨论】:

  • 你应该把上面的语句放在cicle,最后几行也用follower_id代替followers

标签: python data-retrieval twython


【解决方案1】:

代码中的小改动:

import logging  
import time  
import csv  
import twython  
import json  

app_key = "**********"  
app_secret = "**********"  
oauth_token = "***********"  
oauth_token_secret = "**************"  

twitter = twython.Twython(app_key, app_secret, oauth_token, oauth_token_secret)  

followers = twitter.get_followers_ids(screen_name = "Carl_C_Icahn")  

with open('carlfollowers.txt', 'a') as outfile:  
    for follower_id in followers:
        print("Carl Icahn follower:", follower_id)
        json.dump(follower_id, outfile, sort_keys = True, indent = 4)

【讨论】:

  • 此代码不起作用。它所做的只是输出:“('Carl Icahn follower:', u'previous_cursor') ('Carl Icahn follower:', u'previous_cursor_str') ('Carl Icahn follower:', u'next_cursor') ('Carl Icahn follower:', u'ids') ('Carl Icahn follower:', u'next_cursor_str')"
  • 我怎样才能让一个用户的关注者总数不被限制在他的 200k 中的 5000 个?
  • 对于 twitter,一个控制台 python 解决方案 rainbowstream.readthedocs.org/en/latest ,一个 ruby​​ 控制台解决方案 github.com/sferik/t 我使用第二个 @Justin6493
猜你喜欢
  • 2011-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-30
  • 2011-06-08
  • 1970-01-01
  • 2011-10-08
  • 2012-07-20
相关资源
最近更新 更多