Skip to content

Instantly share code, notes, and snippets.

@idan
Created May 2, 2012 22:50
Show Gist options
  • Save idan/2581132 to your computer and use it in GitHub Desktop.
Save idan/2581132 to your computer and use it in GitHub Desktop.
Requests + OAuth, sample usage
import requests
from requests.auth import OAuth1
url = u'https://api.twitter.com/1/account/settings.json'
client_key = u'...'
client_secret = u'...'
resource_owner_key = u'...'
resource_owner_secret = u'...'
queryoauth = OAuth1(client_key, client_secret,
resource_owner_key, resource_owner_secret,
signature_type='query')
headeroauth = OAuth1(client_key, client_secret,
resource_owner_key, resource_owner_secret,
signature_type='auth_header')
bodyoauth = OAuth1(client_key, client_secret,
resource_owner_key, resource_owner_secret,
signature_type='body')
r_query = requests.get(url, auth=queryoauth)
r_header = requests.get(url, auth=headeroauth)
r_body = requests.post(url, auth=bodyoauth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment