Oauth using Birdy Python on Flask: Not able to figure out what to do with the Access Token
Question: This is my code to fetch the tweets based on keyword. Here I am trying to
Authenticate using Birdy Oauth API. But the problem is that I don't seem to
understand why does it say that my token is expired when I enter the Token of
my Application.

**Please give specific feedback on what seems to be the issue here**

    
    
    import datetime
    from config import CONSUMER_KEY, CONSUMER_SECRET, SAVED_ACCESS_TOKEN 
    #Saved access token is a list of containing my apps Access token and 
    #Access token secret as its elements
    
    from birdy.twitter import AppClient
    from app import app
    from app import db
    from models import TweetInfo 
    
    #Create an instance of appclient for the application
    client = AppClient(CONSUMER_KEY, CONSUMER_SECRET, SAVED_ACCESS_TOKEN)
    
    #Add the keywords here which need to be searched over Twitter
    QUERIES = ['#Vespa', '@Vespa']
    
    #A method to fetch all the new entries for statuses 
    #regarding the keywords queried that do not have an entry in the DataBase
    def get_new_tweets():
    """Return number of tweets if any and save them in Database"""
    statuses = [] 
    for query in QUERIES:
        response = client.api.search.tweets.get(q = query, count = 100)
        statuses += response.data.statuses
    
    latest_tweets = 0
    for status in statuses:
        if not db.session.query(TweetInfo).filter(TweetInfo.domain_id ==      status.id_str).count():  #check whether a tweet is already present in the DataBase
            created_at = datetime.datetime.strptime(status.created_at, r"%a %b %d %H:%M:%S +0000 %Y")
            o = TweetInfo(tweet = status.text,
                        posted_by = '{} ({})'.format(status.user.screen_name,
                            status.user.followers_count),
                        recorded_at = datetime.datetime.now(),
                        occured_at = created_at,
                        domain_id = status.id_str)
            latest_tweets += 1
            db.session.add(o)
    db.session.commit()
    return latest_tweets
    


Answer: The Access Token is only valid for some time. So you have to get a new one
with each Connection. Birdy will save it automaticaly. Remember with this auth
you can only read.

Replace this

    
    
    #Create an instance of appclient for the application
    client = AppClient(CONSUMER_KEY, CONSUMER_SECRET, SAVED_ACCESS_TOKEN)
    

With this

    
    
    client = AppClient(CONSUMER_KEY, CONSUMER_SECRET)
    access_token = client.get_access_token()
    

