Created
April 7, 2013 17:28
-
-
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.
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
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