I am trying to write a python script to fetch my tweets using tweepy. I tried 2 versions. They result in 453/403 respectively. Detailed errors below. I have "Free" access to twitter APIs and I have a project with an app(see the screenshot below). Do I need paid access to achieve this?
First version with error:
import tweepy
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_SECRET = ''
authenticator = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
authenticator.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(authenticator, wait_on_rate_limit=True)
query = 'from:my_screen_name -is:retweet'
tweet_cursor = tweepy.Cursor(api.search_tweets, q= query, lang="en",
tweet_mode="extended").items(100)
tweets = [tweet.full_text for tweet in tweet_cursor]
print(tweets)
Error:
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.
Second version with error:
client = tweepy.Client(
consumer_key=CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
access_token=ACCESS_TOKEN,
access_token_secret=ACCESS_SECRET,
bearer_token=BEARER_TOKEN
)
query = 'from:my_screen_name -is:retweet'
tweets = client.search_recent_tweets(query=query, tweet_fields=['context_annotations', 'created_at'], max_results=100)
for tweet in tweets.data:
print(tweet.text)
Error:
When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.