Skip to content

Instantly share code, notes, and snippets.

@smalyshev
Created May 13, 2011 04:34
Show Gist options
  • Select an option

  • Save smalyshev/969975 to your computer and use it in GitHub Desktop.

Select an option

Save smalyshev/969975 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import urlparse
import oauth2 as oauth
import urllib
consumer_key = 'CONSUMERKEY'
consumer_secret = 'CONSUMERSECRET'
url = 'http://localhost:8888/sugar63/service/v4/rest.php'
restparams = {
'input_type': 'json',
'request_type': 'json',
'method':'',
}
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
# Step 1: Get a request token. This is a temporary token that is used for
# having the user authorize an access token and to sign the request to obtain
# said access token.
restparams['method'] = 'oauth_request_token'
resp, content = client.request(url, "POST", body=urllib.urlencode(restparams))
if resp['status'] != '200':
print resp
print content
raise Exception("Invalid response %s." % resp['status'])
request_token = dict(urlparse.parse_qsl(content))
print "Request Token:"
print " - oauth_token = %s" % request_token['oauth_token']
print " - oauth_token_secret = %s" % request_token['oauth_token_secret']
print
authorize_url = request_token['authorize_url']
@collinlee

Copy link
Copy Markdown

Hi I think v5 is wrong here. There is no v5 for 6.3 versions of Sugar. Maybe it's v4?

@smalyshev

Copy link
Copy Markdown
Author

Yes, you are right, v5 was old branch, v4 is correct.

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