pip install python-oauth2
python
import oauth2 as oauth
consumer_key = 'your-consumer-key'
consumer_secret = 'your-consumer-secret'
request_token_url = 'https://example.com/oauth/request_token'
authorize_url = 'https://example.com/oauth/authorize'
access_token_url = 'https://example.com/oauth/access_token'
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
resp, content = client.request(request_token_url, 'GET')
request_token = dict(oauth.parse_response(resp.content))
auth_url = "%s?oauth_token=%s" % (authorize_url, request_token['oauth_token'])
print(auth_url)
resp, content = client.request(access_token_url, 'POST', body='oauth_verifier=%s' % verifier)
access_token = dict(oauth.parse_response(resp.content))