本文整理汇总了Python中twitter.Twitter.fetch_request_token方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.fetch_request_token方法的具体用法?Python Twitter.fetch_request_token怎么用?Python Twitter.fetch_request_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter.Twitter
的用法示例。
在下文中一共展示了Twitter.fetch_request_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Twitdao
# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import fetch_request_token [as 别名]
class Twitdao():
def __init__(self, token=None):
self.token = token
config = md.get_app_config()
if token:
self.twitter = Twitter(
oauth_token=self.token.oauth_token,
oauth_token_secret=self.token.oauth_token_secret,
consumer_key=config.consumer_key,
consumer_secret=config.consumer_secret,
request_token_url=config.request_token_url,
access_token_url=config.access_token_url,
authorize_url=config.authorize_url,
authenticate_url=config.authenticate_url,
api_url=config.api_url,
search_api_url=config.search_api_url
)
else:
self.twitter = Twitter(
consumer_key=config.consumer_key,
consumer_secret=config.consumer_secret,
request_token_url=config.request_token_url,
access_token_url=config.access_token_url,
authorize_url=config.authorize_url,
authenticate_url=config.authenticate_url,
api_url=config.api_url,
search_api_url=config.search_api_url
)
def fetch_request_token(self, callback=None):
return self.twitter.fetch_request_token(callback)
def fetch_access_token(self, verifier):
access_token = self.twitter.fetch_access_token(verifier)
return access_token
def get_authenticate_url(self, request_token, force_login=False):
return self.twitter.get_authenticate_url(request_token, force_login)
def get_authorize_url(self, request_token, force_login=False):
return self.twitter.get_authorize_url(request_token, force_login)
#==========================================================================
def _cache_timeline(self, timeline, **params):
if not 'error' in timeline:
trim_user=params['trim_user'] if 'trim_user' in params else None
include_entities=params['include_entities'] if 'include_entities' in params else None
td=dict(('%s-%s-%s' % (tweet['id_str'], trim_user, include_entities), tweet) for tweet in timeline)
return memcache.set_multi(td, time=TWEET_CACHE_TIME, key_prefix="tweet-")
return False
def _cache_tweet(self, tweet, **params):
if not 'error' in tweet:
trim_user=params['trim_user'] if 'trim_user' in params else None
include_entities=params['include_entities'] if 'include_entities' in params else None
return memcache.set( 'tweet-%s-%s-%s' % (tweet['id_str'], trim_user, include_entities), tweet, time=TWEET_CACHE_TIME,)
return False
def _get_cached_tweet(self, id, **params):
trim_user=params['trim_user'] if 'trim_user' in params else None
include_entities=params['include_entities'] if 'include_entities' in params else None
return memcache.get( 'tweet-%s-%s-%s' % (id, trim_user, include_entities) )
def _del_cached_tweet(self, id, **params):
trim_user=params['trim_user'] if 'trim_user' in params else None
include_entities=params['include_entities'] if 'include_entities' in params else None
return memcache.delete( 'tweet-%s-%s-%s' % (id, trim_user, include_entities) )
#好像不好。
def _cache_users(self, users, **params):
if not 'error' in users:
include_entities = params['include_entities'] if 'include_entities' in params else None
us=dict(('%s-%s' % (user['id_str'], include_entities), user) for user in users)
us.update(dict(('%s-%s' % (user['screen_name'], include_entities), user) for user in users))
return memcache.set_multi(us, key_prefix="user-", time=USER_CACHE_TIME)
return False
def _cache_user(self, user, **params):
if not 'error' in user:
include_entities = params['include_entities'] if 'include_entities' in params else None
return memcache.set_multi({
('id-%s-%s' % (user['id_str'], include_entities)):user,
('screen_name-%s-%s' % (user['screen_name'], include_entities)):user
}, key_prefix="user-", time=USER_CACHE_TIME)
return False
def _get_cached_user_by_id(self, id, **params):
include_entities = params['include_entities'] if 'include_entities' in params else None
return memcache.get('user-id-%s-%s' % (id, include_entities))
def _get_cached_user_by_screen_name(self, screen_name, **params):
include_entities = params['include_entities'] if 'include_entities' in params else None
return memcache.get('user-screen_name-%s-%s' % (screen_name, include_entities))
#删不全啊。
def _del_cached_user_by_id(self, id, **params):
include_entities = params['include_entities'] if 'include_entities' in params else None
#.........这里部分代码省略.........