Skip to content

Instantly share code, notes, and snippets.

@screeley
Created May 5, 2011 20:21
Show Gist options
  • Save screeley/957841 to your computer and use it in GitHub Desktop.
Save screeley/957841 to your computer and use it in GitHub Desktop.
OAuth Embedly
import oauth2 as oauth
import time
import urllib, urllib2
# Set the API endpoint
url = "http://pro.embed.ly/1/preview"
urls = ['http://google.com', 'http://apple.com']
params = {
'oauth_version': "1.0",
'oauth_nonce': oauth.generate_nonce(),
'oauth_timestamp': int(time.time()),
'urls': ','.join([urllib.quote(u) for u in urls])
}
# Set up instances of our Token and Consumer. The Consumer.key and
# Consumer.secret are given to you by the API provider.
token = oauth.Token(key="", secret="")
consumer = oauth.Consumer(key=":key", secret=":secret")
# Create our request. Change method, etc. accordingly.
req = oauth.Request(method="GET", url=url, parameters=params)
# Sign the request.
signature_method = oauth.SignatureMethod_HMAC_SHA1()
req.sign_request(signature_method, consumer, token)
response = urllib2.urlopen(req.to_url())
print response.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment