Reputation: 51
Does anyone know if it is still possible to collect the number of followers for a given Twitter account using the free version of the Twitter v2 API (after Feb 9th, 2023)?
I tried getting access to the API using the following code, but got the following error:
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}')
Error: Forbidden: 403 Forbidden 453 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve
Upvotes: 3
Views: 4345
Reputation: 7091
With the v2 API you can only access data for yourself or the authenticated user.
With 1.1 API you can access public data, including followers for any account like this:
https://api.twitter.com/1.1/users/show.json?screen_name=alfrednerstu
Based on the code and error message it looks like you're using the 1.1 API already but that your Developer account is on an old Essential plan. You need to upgrade to the new Free plan.
Upvotes: 0
Reputation: 137
The Twitter Api is still working in 2023, but sometimes the api credentials in the app get suspended , so you just need to create new app in the twitter developper platform;
I found this interesting 2023 tutorial of how to extract twitter data in python , and it still working, here is the videos links
Extract Twitter Data from Twitter API in Python Using Tweepy [2023 Tutorial] https://youtu.be/EIuvnhlmn24
Get Twitter API in 2023 for FREE ( Still Working !) https://youtu.be/PkacG2UYMps
Upvotes: -1
Reputation: 599
I think you are using twitter api v1 while you have access only to API v2
In api v2 free tier you can access only to post tweets and GET /2/users/me
, where you can get user details including follower count
https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user
Upvotes: 2