def method_call(request, method): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET) if request.user.is_authenticated(): api.token = get_token_for_user(request.user) auth = True else: auth = False data = api.get(method, auth=auth, photo_id='6110054503') return HttpResponse(simplejson.dumps(data))
def oauth_access(request): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET) data = api.access_token(request) if data: data = bunchify(data) fs, created = FlickrUser.objects.get_or_create(user=request.user) fs.token = data.token fs.nsid = data.oauth.user.nsid fs.username = data.oauth.user.username fs.full_name = data.oauth.user.fullname fs.perms = data.oauth.perms._content fs.save() return HttpResponseRedirect(reverse('flickr_auth')) raise Exception, 'Ups! No data...'
def oauth(request): token = get_token_for_user(request.user) if not token: api = FlickrApi(FLICKR_KEY, FLICKR_SECRET) url = api.auth_url(request, perms=PERMS, callback=request.build_absolute_uri(reverse('flickr_complete'))) return HttpResponseRedirect(url) else: api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token, fallback=False) try: data = api.get('flickr.test.login') except: # # FlickrUnauthorizedCall: fs = FlickrUser.objects.get(user=request.user) fs.token = None fs.perms = None fs.save() return HttpResponseRedirect(reverse('flickr_auth')) return render_to_response("flickr/auth_ok.html", {'token': token, }, context_instance=RequestContext(request))
def __init__(self): super(FlickrCommand, self).__init__() self.FLICKR_KEY = getattr(settings, 'FLICKR_KEY', None) if not self.FLICKR_KEY: raise CommandError, 'No FLICKR_KEY in settings. %s' % self.help_text self.FLICKR_SECRET = getattr(settings, 'FLICKR_SECRET', None) if not self.FLICKR_SECRET: raise CommandError, 'No FLICKR_SECRET in settings. %s' % self.help_text self.api = FlickrApi(self.FLICKR_KEY, self.FLICKR_SECRET)
def get_photo_details_jsons(photo_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) info = api.get(method='photos.getInfo', photo_id=photo_id) time.sleep(1) sizes = api.get(method='photos.getSizes', photo_id=photo_id) time.sleep(1) exif = api.get(method='photos.getExif', photo_id=photo_id) time.sleep(1) geo = api.get(method='photos.geo.getLocation', photo_id=photo_id) return info, sizes, exif, geo
def oauth(request): token = get_token_for_user(request.user) if not token: api = FlickrApi(FLICKR_KEY, FLICKR_SECRET) url = api.auth_url(request, perms=PERMS, callback=request.build_absolute_uri( reverse('flickr_complete'))) return HttpResponseRedirect(url) else: api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token, fallback=False) try: data = api.get('flickr.test.login') except: # # FlickrUnauthorizedCall: fs = FlickrUser.objects.get(user=request.user) fs.token = None fs.perms = None fs.save() return HttpResponseRedirect(reverse('flickr_auth')) return render_to_response("flickr/auth_ok.html", { 'token': token, }, context_instance=RequestContext(request))
def get_photo_exif_json(photo_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) exif = api.get(method='photos.getExif', photo_id=photo_id) return exif
def get_collection_info_json(collection_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) return bunchify(api.get(method='collections.getInfo', collection_id=collection_id))
def get_collections_tree_json(nsid, token): """tree for user or tree for collection""" api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) return bunchify(api.get(method='collections.getTree', user_id=nsid))
def get_user_json(nsid, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) return bunchify(api.get(method='flickr.people.getInfo', user_id=nsid))
def get_photoset_photos_json(photoset_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) return bunchify(api.get(method='flickr.photosets.getPhotos', photoset_id=photoset_id))
def get_photosets_json(nsid, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) return bunchify(api.get(method='flickr.photosets.getList', user_id=nsid, page=1, per_page=500))
def get_photo_geo_json(photo_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) geo = api.get(method='photos.geo.getLocation', photo_id=photo_id) return geo
def get_photo_sizes_json(photo_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) sizes = api.get(method='photos.getSizes', photo_id=photo_id) return sizes
def get_photo_info_json(photo_id, token): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) info = api.get(method='photos.getInfo', photo_id=photo_id) return info
def get_photos_json(nsid, token, page=1, per_page=500, min_upload_date=None, extras=None): api = FlickrApi(FLICKR_KEY, FLICKR_SECRET, token) return bunchify(api.get(method='people.getPhotos', user_id=nsid, page=page, per_page=per_page, min_upload_date=min_upload_date, extras=extras))