Forums

3-legged Oauth for my Twitter Python script

I have the below basic python script and I would like to use the 3-legged Oauth that the Twitter API makes available to allow anyone to sign in with their Twitter account and use the script.

At the moment they can simply enter their Keys/Tokens to use it but I would like a standard Twitter user to be able to use it and not just a developer who knows these.

import tweepy

print('Please enter your Consumer Key')
consumer_key = input()
print('Please enter your Consumer Secret')
consumer_secret = input() 
print('Please enter your Access Token')
key = input()
print('Please enter your Access Secret')
secret = input()

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
api = tweepy.API(auth, wait_on_rate_limit=True)

screen_name = auth

for follower in api.followers(screen_name): 
    print(follower.screen_name)

Do I have to use my script in a web app to make this possible or is there something I can add to the script for this authorisation?

I would like it to work similarly to a third party app that you would grant access to get/post from your twitter.

I believe that, if you want it to work as a third party app, you will need to make it a web app. The documentation for the Twitter API and tweepy will be your best reference for how to do that.