How to Autenticate on Twitter using Tweepy oauth

Problem: 

You need a way to use diferent bots using the same developer API.

Solution:

I foun a trick that you can use directly in python with a single script; here the point is that you have to request the PIN on the execution time so you will not able to save the key's on execution time.

1.- Run this code script.

2.- Open the web link after login with your external twitter account to get the PIN code.

3.- Continue execution  after you enter the PIN.

import tweepy
# api credentials 
auth = tweepy.OAuthHandler('api key', 'api secret','oob')
# get access token from the user and redirect to auth URL
auth_url = auth.get_authorization_url()
print('Authorization URL: ' + auth_url)
# ask user to verify the PIN generated in broswer
verifier = input('PIN: ').strip()
auth.get_access_token(verifier)
print('ACCESS_KEY = "%s"' % auth.access_token)
print('ACCESS_SECRET = "%s"' % auth.access_token_secret)
# authenticate and retrieve user name
auth.set_access_token(auth.access_token, auth.access_token_secret)
api = tweepy.API(auth)
user = api.verify_credentials()
print('Name: ' + str(user.name))


Source:

By suracoza
https://gist.github.com/hezhao/4772180#gistcomment-3972371