Created
February 28, 2010 12:23
-
-
Save thruflo/317559 to your computer and use it in GitHub Desktop.
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
| class Flickr(RequestHandler): | |
| def post(self, action): | |
| self.get(action) | |
| def get(self, action): | |
| client = flickrapi.FlickrAPI( | |
| config.FLICKR_API_KEY, | |
| config.FLICKR_API_SECRET, | |
| store_token = False | |
| ) | |
| if action == 'callback': | |
| frob = self.request.get('frob') | |
| rsp = client.auth_getToken(frob=frob, auth_token=None, format='json') | |
| # jsonFlickrApi({...}) --> becomes {...} | |
| rsp = rsp[14:-1] | |
| data = demjson.decode(rsp, encoding='utf8') | |
| if data['stat'] == u'ok': | |
| self.session = session.Session(set_cookie_expires=False) | |
| self.session['flickr_data'] = data['auth'] | |
| came_from = self.request.get('camefrom', u'') | |
| redirect_to = came_from and came_from or config.site_url | |
| self.redirect('%s?update_auth_service=flickr' % redirect_to) | |
| elif action == 'login': | |
| url = client.web_login_url(perms='read') | |
| self.redirect(url) | |
| else: | |
| return NotImplemented | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment