コード例 #1
0
 def get(self):
     session = get_current_session()        
     frob = self.request.get('frob') 
     if not frob:
         self.response.out.write("no frob")
         return
     
     nickname = session.get("nickname", 0)
     if not nickname:
         self.response.out.write("no nickname")
         return
     userinfo = UserInfo.gql("WHERE nickname=:1", nickname).get()
     if not userinfo:
         self.response.out.write("no user")
         return
          
     flickr_api_key = userinfo.flickr_api_key
     flickr_api_secret = userinfo.flickr_api_secret
     flickr = flickrapi.FlickrAPI(
                 flickr_api_key, 
                 flickr_api_secret, 
                 store_token=False)
         
     try:
         token = flickr.get_token(frob)
         e = TokenEntity.gql("WHERE nickname=:1", nickname).get()
         if not e:
             e = TokenEntity()
         e.username = nickname
         e.token = token
         e.put()
         #session['flickr_token'] = token
     except Exception as e:
         print "Unexpected error:", e.message
     self.redirect('/setting')
コード例 #2
0
ファイル: tokencache.py プロジェクト: marvelliu/flickr2weibo
 def forget(self):
     '''Removes the cached token'''
     
     if self.username in self.memory:
         del self.memory[self.username]
     
     name = self.getUsername()
     
     entities = TokenEntity.gql("WHERE username:=", name)
     
     for entity in entities:
         entity.delete()
コード例 #3
0
ファイル: tokencache.py プロジェクト: marvelliu/flickr2weibo
    def get_cached_token(self):
        """Read and return a cached token, or None if not found.

        The token is read from the cached token file.
        """

        # Only read the token once
        if self.username in self.memory:
            return self.memory[self.username]
        
        name = self.getUsername()
        
        entities = TokenEntity.gql("WHERE username=:1",name)
        #entities = ""
        
        if not entities:
            return None
        for entity in entities:
            return entity.token.strip()
        return None
コード例 #4
0
ファイル: tokencache.py プロジェクト: marvelliu/flickr2weibo
    def set_cached_token(self, token):
        """Cache a token for later use."""

        # Remember for later use
        self.memory[self.username] = token

        name = self.getUsername()
        
        entities = TokenEntity.gql("WHERE username:="******""
        for entity in entities:
            e = entity
            break
        if not e:
            e = TokenEntity()
        print "eeeeeeeeee"
        e.apikey = self.api_key
        e.username = username
        e.token = token
        e.put()
        print "xxxxxxxxxxxxxxx"
コード例 #5
0
ファイル: authv2.py プロジェクト: marvelliu/flickr2weibo
def GetFlickrToken(nickname):
    t = TokenEntity.gql("WHERE username=:1", nickname).get()
    if t:
        return t.token
    return None