def setUp(self): import tempfile from flickrapi.tokencache import OAuthTokenCache from flickrapi.auth import FlickrAccessToken # Use mkdtemp() for backward compatibility with Python 2.7 self.tc_path = tempfile.mkdtemp() self.tc = OAuthTokenCache('123-456', path=self.tc_path) self.token = FlickrAccessToken( u'nümbér', u'səcret-tøken', u'read', u'My Full Name™', u'üsernåme', u'user—nsid', )
def _load_token(self): try: token_data = self._dataHelper.get_secure_data(self._token_key) if token_data is not None: return FlickrAccessToken(unicode(token_data["oauth_token"]), unicode(token_data["oauth_token_secret"]), unicode(token_data["access_level"]), unicode(token_data["fullname"]), unicode(token_data["username"]), unicode(token_data["user_nsid"])) except: pass return None
def token(self): '''Return the cached token for this API key, or None if not found.''' # Only read the token once if (self.api_key, self.lookup_key) in self.RAM_CACHE: return self.RAM_CACHE[self.api_key, self.lookup_key] db = sqlite3.connect(self.filename) curs = db.cursor() curs.execute('''SELECT oauth_token, oauth_token_secret, access_level, fullname, username, user_nsid FROM oauth_tokens WHERE api_key=? and lookup_key=?''', (self.api_key, self.lookup_key)) token_data = curs.fetchone() if token_data is None: return None return FlickrAccessToken(*token_data)
def get_flickr(self, api_key, api_secret, token, token_secret): return flickrapi.FlickrAPI(api_key, api_secret, token=FlickrAccessToken( token, token_secret, u'write'))