gpt4 book ai didi

python - 属性错误 : 'API' object has no attribute 'followers_ids'

转载 作者:行者123 更新时间:2023-12-05 00:52:38 27 4
gpt4 key购买 nike

我正在尝试使用 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.0API.followers_ids 重命名为 API.get_follower_ids .

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

关于python - 属性错误 : 'API' object has no attribute 'followers_ids' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69751853/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com