Created
October 7, 2011 05:38
-
-
Save joshbirk/1269547 to your computer and use it in GitHub Desktop.
Python script using rest-python-client with Force.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Also, had to update the httplib in python, otherwise got a float error
if i may ask, how did you update httplib? I am getting the float error and i just installed the python-httplib2
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
Sorry, its:
http://code.google.com/p/python-rest-client/
For the REST client