我一直在尝试使用Tweepy或Twython与Twitter API来搜索特定的hashtag,提取用户使用hashtage进行推文的用户名,然后查看其中有多少人用户相互关注。我的最终目标是用NetworkX显示连接。Python:检查Twitter用户A以下用户B
到目前为止,我已经能够搜索哈希标签并获得用户的推特列表。但是,我无法弄清楚如何看清谁在谁的名单上。我终于找到了一个友情查找工作,但后来才意识到该参数只搜索经过身份验证的用户(我)的朋友。
这里是代码的最新版本:
from twython import Twython
import tweepy
# fill these in from Twitter API Dev
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth, wait_on_rate_limit=True)
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET)
# Search for hashtag, limit number of users
try:
search_results = twitter.search(q='energy', count=5)
except TwythonError as e:
print e
test5 = []
for tweet in search_results['statuses']:
if tweet['user']['screen_name'] not in test5:
test5.append((tweet['user']['screen_name']).encode('utf-8'))
print test5
# Lookup friendships
relationships = api.lookup_friendships(screen_names=test5[0:5])
for relationship in relationships:
if relationship.is_following:
print("User is following", relationship.screen_name)
谢谢!
我认为,对于每5000个名字的过度请求,您必须等待60秒才能提出下一个请求。 – thesonyman101