Skip to content

Instantly share code, notes, and snippets.

@embedly
Created March 11, 2010 21:03
Show Gist options
  • Save embedly/329646 to your computer and use it in GitHub Desktop.
Save embedly/329646 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib
import urllib2
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
raise ImportError("Need a json decoder")
ACCEPTED_ARGS = ['maxwidth', 'maxheight', 'format']
def get_oembed(url, **kwargs):
"""
Example Embedly oEmbed Function
"""
api_url = 'http://api.embed.ly/v1/api/oembed?'
params = {'url':url }
for key, value in kwargs.items():
if key not in ACCEPTED_ARGS:
raise ValueError("Invalid Argument %s" % key)
params[key] = value
oembed_call = "%s%s" % (api_url, urllib.urlencode(params))
return json.loads(urllib2.urlopen(oembed_call).read())
if __name__ == "__main__":
urls = ["http://vimeo.com/9503416",
"http://twitpic.com/13whni"]
for url in urls:
print "\n\nurl: %s\n" % url
print get_oembed(url)
print "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment