AttributeError: 'API' object has no attribute 'followers_ids'

AttributeError: 'API' object has no attribute 'followers_ids'

我正在尝试使用 Tweepy 从特定用户中提取关注者列表。然而,我 运行 进入一个错误说 AttributeError: 'API' object has no attribute 'followers_ids'。然而,这段代码在另一台机器上运行流畅,但在我的机器上运行不流畅。我试图重新安装 Tweepy 但没有任何改变。请帮忙T.T

    import os
    import sys
    import json
    import time
    import math
    from tweepy import Cursor
    import tweepy
    from tweepy import OAuthHandler
    import datetime
    
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)
    
    MAX_FRIENDS = 10000
    
    def paginate(items, n):
        """Generate n-sized chunks from items"""
        for i in range(0, len(items), n):
            yield items[i:i+n]
        
    def get_followers(screen_name):
        # get followers for a given user
        fname = "users/{}/followers.json".format(screen_name)
        max_pages = math.ceil(MAX_FRIENDS / 5000)
        with open(fname, 'w') as f:
            for followers in Cursor(api.followers_ids, screen_name=screen_name).pages(max_pages):
                for chunk in paginate(followers, 100):
                    users = api.lookup_users(user_ids=chunk)
                    for user in users:    
                        f.write(json.dumps([user.id, user.screen_name, user.location, str(user.created_at)], sort_keys=True)+"\n")                 
                if len(followers) == 5000:
                    print("More results available. Sleeping for 60 seconds to avoid rate limit")
                    time.sleep(60)
        print("task completed for " + screen_name)
        

Tweepy v4.0.0 renamed API.followers_ids to API.get_follower_ids.

您可能在另一台机器上使用旧版本的 Tweepy。