Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tweepy检查用户A是否在跟踪用户B?_Python_Twitter_Tweepy - Fatal编程技术网

Python Tweepy检查用户A是否在跟踪用户B?

Python Tweepy检查用户A是否在跟踪用户B?,python,twitter,tweepy,Python,Twitter,Tweepy,我有这个代码(不是所有的代码),它基本上得到了20个最新的追随者。问题是它会向我已经在跟踪的人发出跟踪请求。这不会是一个问题,但twitter限制了您可以发出的请求数量 followers = api.followers() following = api.friends() tofollow = [x for x in followers if x not in following] for u in tofollow: try: u.follow() numbe

我有这个代码(不是所有的代码),它基本上得到了20个最新的追随者。问题是它会向我已经在跟踪的人发出跟踪请求。这不会是一个问题,但twitter限制了您可以发出的请求数量

followers = api.followers()
following = api.friends()
tofollow = [x for x in followers if x not in following]
for u in tofollow:
   try:
      u.follow()
      number_followed+=1
      print number_followed,". ", u.screen_name
   except tweepy.TweepError as err:
    print "Error: when following ", u.screen_name
我想这与我的行为有关


有什么想法吗?

我认为,如果你想在twitter上查询整个集合,而不是最近的20个,你应该使用光标

例如:

tweepy.Cursor(api.followers).items()
此外,如果您不想违反twitter速率限制,则可以在初始化api对象时使用以下行:

api = tweepy.API(auth, wait_on_rate_limit=True)
希望能有帮助。以下是一个例子:

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth, wait_on_rate_limit=True)

friends = api.friends_ids(api.me().id)
print("You follow", len(friends), "users")

for follower in tweepy.Cursor(api.followers).items():
    if follower.id != api.me().id:
        if follower.id in friends:
            print("You already follow", follower.screen_name)
        else:
            follower.follow()
            print("Started following", follower.screen_name)

什么是追随者和追随者?您确定它们都以相同的格式返回用户吗?