How to do 3-legged authentication using tweepy for web app

20 Views Asked by At

I want to do 3-legged authentication for twitter using tweepy for a web app. The problem I am facing is that for a web app there is no oauth_verifier hence I cannot do it by the documentation https://docs.tweepy.org/en/stable/authentication.html and another problem that I am facing is that in my code:

app = Flask(__name__)
@app.route('/')
def index():
    oauth1_user_handler = tweepy.OAuth1UserHandler(
    consumer_key,
    consumer_secret,
    callback=callback_url
    )
    sign=oauth1_user_handler.get_authorization_url(signin_with_twitter=True)
    print(sign)
    parsed_url = urlparse(sign)
    query_params = parse_qs(parsed_url.query)

    oauth_token = query_params.get('oauth_verifier', [None])[0]

    print("OAuth Token:", oauth_token)
    access_token, access_token_secret = oauth1_user_handler.get_access_token(oauth_token)
    client=TwitterClientV2(consumer_key,consumer_secret,access_token,access_token_secret)
    post=client.client.create_tweet(text="pls work")
    return redirect(sign)

@app.route('/callback')
def callback():
    return "why am i here"
if __name__ == '__main__':
    app.run()

Is that I want to send the oauth_token to callback but I cannot find a way to do it. It would be a big help if anyone could help me.

0

There are 0 best solutions below