Search code examples
pythonapitwitter

Where can I get Twitter access Token for python app?


Please take a look at the python code first.

import tweepy

# necessary keys for authorisation 
API_KEY = 'your_api_key'
API_SECRET = 'your_api_secret'
ACCESS_TOKEN = 'your_access_token'
ACCESS_TOKEN_SECRET = 'your_access_token_secret'

# API authorisation 
auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

# get tweets by keywords 
api = tweepy.API(auth)
tweets = api.search(q=['Python'], count=10)

for tweet in tweets:
    print('-----------------')
    print(tweet.text)

I wanted to make the coed above work, but after I requested an API on https://developer.twitter.com/en/apps/ they only gave me API Key, API Key secret and Bearer Token. Where are ACCESS_TOKEN and ACCESS_TOKEN_SECRET? As you can see in the picture below there was no ACCESS_TOKEN and ACCESS_TOKEN_SECRET

enter image description here

Please let me know how I can solve it. Thank you in advance.


Solution

  • According to this link lower on the page where you can see your API tokens it should allow you to generate Access tokens as well

    https://developer.twitter.com/ja/docs/basics/authentication/guides/access-tokens