def create_api_instance(tokens):
"""return authenticated tweepy api instance. In order to do that
you need to provide a dictionary which values are the four tokens
provided by apps.twitter when registering an app.
Parameters
----------
tokens : dict{'api_key': <api_key>, 'api_secret': <api_secret>,
'access': <access>, 'access_secret': <secret_access>}
"""
auth = tweepy.OAuthHandler(tokens['api_key'], tokens['api_secret'])
auth.set_access_token(tokens['access'], tokens['access_secret'])
if 'proxy' in tokens:
api = tweepy.API(auth, proxy=tokens['proxy'])
else:
api = tweepy.API(auth)
return api
评论列表
文章目录