Twitter API v2 - 免费版 - 获取粉丝数量 - 2023

问题描述 投票:0回答:1

有谁知道是否仍然可以使用免费版本的 Twitter v2 API(2023 年 2 月 9 日之后)收集给定 Twitter 帐户的关注者数量?

我尝试使用以下代码访问 API,但出现以下错误:

import tweepy
import requests

# Replace with your own keys and tokens

API_KEY = 'persnal key'
API_SECRET_KEY = 'persnal key'
ACCESS_TOKEN = 'persnal key'
ACCESS_TOKEN_SECRET = 'persnal key'

# Authenticate using your keys and tokens

auth = tweepy.OAuthHandler(API_KEY, API_SECRET_KEY)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# Create the API object

api = tweepy.API(auth)

def get_followers_count(screen_name):
    user = api.get_user(screen_name=screen_name)  # Update this line
    return user.followers_count

# Replace 'screen_name' with the desired Twitter account's screen name

screen_name = 'account_x'
followers_count = get_followers_count(screen_name)

print(f'The number of followers for {screen_name} is: {followers_count}')

错误: 禁止:403 禁止 453 - 您目前拥有基本访问权限,其中仅包括对 Twitter API v2 端点的访问权限。如果您需要访问此端点,则需要通过开发人员门户申请提升访问权限。您可以在这里了解更多信息:https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve

python api twitter tweepy twitterapi-python
1个回答
0
投票

我认为您使用的是 twitter api v1,而您只能访问 API v2

在 api v2 免费层中,您只能访问发布推文和

GET /2/users/me
,您可以在其中获取用户详细信息,包括关注者人数

https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user

© www.soinside.com 2019 - 2024. All rights reserved.