Skip to content

Instantly share code, notes, and snippets.

@zsprackett
Forked from jmertic/gist:5844722
Created June 24, 2013 16:48
Show Gist options
  • Save zsprackett/5851549 to your computer and use it in GitHub Desktop.
Save zsprackett/5851549 to your computer and use it in GitHub Desktop.
import json
import requests
url = "<<instanceurl>>/rest/v10/oauth2/token"
payload = {"grant_type":"password","username":"<<username>>","password":"<<password>>","client_id":"sugar"}
r = requests.post(url, data=json.dumps(payload))
response = json.loads(r.text)
if response[u'error']:
print response[u'error_message']
token = response[u'access_token']
print 'Success! OAuth token is ' + token
url = "<<instanceurl>>/rest/v10/me"
headers = { "Content-Type" : "application/json", "OAuth-Token": token }
r = requests.get(url, headers=headers);
response = json.loads(r.text)
if response[u'error']:
print response[u'error_message']
print r.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment