我抓住了其他帐户的关注者列表,需要全部关注。但是默认循环遍历整个用户列表,包括我已经关注的人,所以我需要排除它们。基本上,我检查show_friendship方法是否从json节点返回False,如果发生则跟随用户。出于某种原因,第二个if语句之后的代码(如果friendship ==“False”:)从未开始,我也无法关注任何人。
这是我创建的方法:
def follow_account_followers(account_followers_ids):
followers_count = 0
for account_follower_id in account_followers_ids:
if followers_count < 7:
try:
friendship = api.show_friendship(target_id=account_follower_id)[1].followed_by
print friendship
print account_follower_id
followers_count += 1
if friendship == "False": #check if we follow the user from array (not a bool value)
print followers_count
api.create_friendship(target_id=account_follower_id[follow])
print 'Following {}'.format(account_follower_id)
else:
continue
except tweepy.error.TweepError:
continue