2

I recently created a Twitter account, and I want to access weather-related information using an API. In the developer section, under the “Overview” section, it says following.

LIMITED V1.1 ACCESS ONLY Standalone Apps live outside of Projects. This means that they can’t use the the most current v2 Twitter API endpoints.

And after I enter the following code in Python:

Forbidden: 403 Forbidden 453 - You currently have access to Twitter API v2 endpoints and limited v1.1 endpoints only. If you need access to this endpoint, you may need a different access level. You can learn more here: Getting Started with the Twitter API | Docs | Twitter Developer Platform

import tweepy
API_KEY = '----'`your text`
API_SECRET_KEY = '----'
ACCESS_TOKEN = '---'
ACCESS_TOKEN_SECRET = '---'

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

api = tweepy.API(auth)

def get_followers_count(screen_name):
   user = api.get_user(screen_name=screen_name)  
   return user.followers_count

screen_name = 'account_x'
followers_count = get_followers_count(screen_name)

print(f'The number of followers for {screen_name} is: {followers_count}')
mehrdad
  • 31
  • 2
  • Musk is making some Twitter API functions paid only. As the error says, you can only access some v1.1 endpoints. – SimonUnderwood May 20 '23 at 17:57
  • looks like Twitter is restricting the 1.1 API (which is what`tweepy.API` is) and favouring 2.0 (which is `tweepy.Client` - https://docs.tweepy.org/en/stable/authentication.html#twitter-api-v2 ) – slothrop May 20 '23 at 17:57
  • Thanks. I changed thecode to, when I run I have error. I wrote try, except. it have entered to except, and show this : 'error during authentication' /n import tweepy /n client = tweepy.Client(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_token_secret) /n try: client.verify_credentials() print("Authentication ok") except: print("error during authentication") – mehrdad May 21 '23 at 02:45

0 Answers0