Skip to content

Instantly share code, notes, and snippets.

@felipecruz
Created January 16, 2012 14:21
Show Gist options
  • Save felipecruz/1621083 to your computer and use it in GitHub Desktop.
Save felipecruz/1621083 to your computer and use it in GitHub Desktop.
# pip requirements.txt
# requests==0.9.1
# requests-oauth==0.2.3
# -e git://github.com/simplegeo/python-oauth2.git@a83f4a297336b631e75cba102910c19231518159#egg=oauth2-dev
import sys
import requests
from oauth_hook import OAuthHook
APP_ID = ""
APP_SECRET = ""
AUTH_URL = "http://api.riodatamine.com.br/rest/request-token?" \
"app-id=%s&app-secret=%s"
SERVICE_URL = "url do servico desejado"
my_config = {'verbose': sys.stderr}
OAuthHook.consumer_key = APP_ID
OAuthHook.consumer_secret = APP_SECRET
oauth_hook = OAuthHook('', '')
client = requests.session(hooks={'pre_request' : oauth_hook})
request = client.get(AUTH_URL % (APP_ID, APP_SECRET))
access_token = request.headers['x-access-token']
access_token_expires = request.headers['x-access-token-expires']
headers = { 'Authorization' : access_token}
request = requests.get(SERVICE_URL, headers=headers, config=my_config)
print request.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment