Skip to content

Instantly share code, notes, and snippets.

@joshbirk
Created October 7, 2011 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshbirk/1269547 to your computer and use it in GitHub Desktop.
Save joshbirk/1269547 to your computer and use it in GitHub Desktop.
Python script using rest-python-client with Force.com
import os
import urlparse
import urllib
from restful_lib import Connection
consumer_key = 'CONSUMERKEY'
callback = 'https://login.salesforce.com/services/oauth2/success'
login_url = 'https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id='+consumer_key+'&redirect_uri='+callback
os.system("open '"+login_url+"'");
url_result = raw_input('If the page says "Remote Access Application Authorization", what is the URL?')
result = dict(urlparse.parse_qsl(url_result.split("success#")[1]));
token = urllib.unquote(result["access_token"])
instance_url = urllib.unquote(result["instance_url"])
conn = Connection(instance_url+'/services/data/v20.0')
result = conn.request_get('query',args={'q':'SELECT ID FROM CONTACT'},headers={'Authorization': 'OAuth '+token});
print result
@joshbirk
Copy link
Author

joshbirk commented Oct 7, 2011

Sorry, its:
http://code.google.com/p/python-rest-client/

For the REST client

@joshbirk
Copy link
Author

joshbirk commented Oct 7, 2011

Also, had to update the httplib in python, otherwise got a float error

@manugarri
Copy link

if i may ask, how did you update httplib? I am getting the float error and i just installed the python-httplib2

@joshbirk
Copy link
Author

joshbirk commented Jan 9, 2014

So for the insanely late response to this - somehow this got lost in my notifications.

IIRC, you need to be sure you are using the latest version of Python. If you are on OSX, I think the default is old and gives you the float error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment