def __generatorValidToken(self,site_id):
        '''
        update a invalid token
        '''
        if self.db is None:
            raise TokenGeneratorError("0", "数据库创建链接失败")
#            self.logger.error("数据库创建链接失败")
            return None
        result = self.db.query("SELECT uid,username,password FROM tb_account_info WHERE platform_id = " + str(site_id) + " AND is_valid=0  ORDER BY assign_counter ASC")
        tokens=[]
        for account_info in result:
            access_token,expires_in = WeiboTokenGenerator.loginAndGetToken(account_info["username"],account_info["password"])
            self.db.update("UPDATE access_token = '" + access_token + "',expires_in='" + expires_in + "' WHERE uid=" + account_info["uid"])
            token = dict([("access_token",access_token),("expires_in",expires_in)])
            tokens.append(token)
        return tokens
Пример #2
0
def weibo_api(url, method):
    '''
    get avaliable access token to proxy the url request.
    '''
    APP_KEY = '3231340587' # app key
    APP_SECRET = '94c4a0dc3c4a571b796ffddd09778cff' # app secret
    CALLBACK_URL = 'http://120.weibomanager.sinaapp.com/callback.php' # callback url
    client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
    tokenGenerator = AutoTokenGenerator()
#    access_token,expires_in = tokenGenerator.generatorToken(1);
    access_token,expires_in = WeiboTokenGenerator.loginAndGetToken("*****@*****.**","5845211314");
#    print access_token,expires_in
    client.set_access_token(access_token=access_token,expires_in=expires_in)
    methodResult = getattr(client, url)()
#    encodedResult = str(methodResult).decode("UTF-8")
#    return encodedResult.encode("UTF-8")
    encodedResult = json.dumps(methodResult)
    return encodedResult