skip to Main Content

I am getting below error while trying to run the python script to replay a tweet on my account.


import tweepy

#Consumer keys and access tokens, used for OAuth
API_KEY = “MY_API_KEY”
API_SECRET_KEY = “MY_API_SECRET_KEY”
ACCESS_TOKEN = “MY_ACCESS_TOKEN”
ACCESS_TOKEN_SECRET = “MY_ACCESS_TOKEN_SECRET”

#OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(API_KEY, API_SECRET_KEY)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

#Creation of the actual interface, using authentication
api = tweepy.API(auth)

mentions= api.mentions_timeline()
for mention in mentions:
    print(str(mention.id)+" - "+ mention.text)
    print("heeloo")

The main idea is to replay to any one who mention my account using api.mentions_timeline()

but I have issue " 453 – You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product
"

also I already upgrade my account to basic 100$ per month
Can anyone help me?Thanks

2

Answers


  1. You have to use the V2 of the API if you want to get or to post tweets, not the V1.

    With Tweepy, that means using the Client class and the get_users_mentions and create_tweet methods. You can find examples here (select the API v2 tab) on their website.

    For example, if you want to post a tweet:

    import tweepy
    
    consumer_key = ""
    consumer_secret = ""
    access_token = ""
    access_token_secret = ""
    
    client = tweepy.Client(
        consumer_key=consumer_key, consumer_secret=consumer_secret,
        access_token=access_token, access_token_secret=access_token_secret
    )
    
    # Create Tweet
    
    # The app and the corresponding credentials must have the Write permission
    
    # Check the App permissions section of the Settings tab of your app, under the
    # Twitter Developer Portal Projects & Apps page at
    # https://developer.twitter.com/en/portal/projects-and-apps
    
    # Make sure to reauthorize your app / regenerate your access token and secret 
    # after setting the Write permission
    
    response = client.create_tweet(
        text="This Tweet was Tweeted using Tweepy and Twitter API v2!"
    )
    
    print(f"https://twitter.com/user/status/{response.data['id']}")
    

    Or, if you want to get an user’s mentions:

    user_id = 2244994945
    
    response = client.get_users_mentions(user_id)
    
    # By default, only the ID and text fields of each Tweet will be returned
    for tweet in response.data:
        print(tweet.id)
        print(tweet.text)
    
    # By default, the 10 most recent Tweets will be returned
    # You can retrieve up to 100 Tweets by specifying max_results
    response = client.get_users_mentions(user_id, max_results=100)
    

    (you may need to use client.get_users_mentions(user_id, user_auth=True))

    Login or Signup to reply.
  2. Basic plan doesn’t have access to streaming endpoints. its for Pro plan users and above. More info is available in the products documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search