Skip to content

Instantly share code, notes, and snippets.

@rsadwick
Created April 7, 2013 17:28
Show Gist options
  • Save rsadwick/5331439 to your computer and use it in GitHub Desktop.
Save rsadwick/5331439 to your computer and use it in GitHub Desktop.
Calling instagram api from Django view. Returns json to easily wire up into a js ajax call.
def get_instagram(request):
#define tag here:
tag = 'jesus'
req = urllib2.Request("https://api.instagram.com/v1/tags/" + tag + "/media/recent?access_token=TOKEN_GOES_HERE&count=50")
opener = urllib2.build_opener()
instagram = opener.open(req)
json = simplejson.load(instagram)
images = []
for image in json['data']:
images.append({'thumbnail' : image['images']['thumbnail'], 'standard' : image['images']['standard_resolution'], 'caption' : image['caption'] })
return HttpResponse(simplejson.dumps(images), mimetype = 'text/json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment