本文整理汇总了Python中twitter.oauth.write_token_file函数的典型用法代码示例。如果您正苦于以下问题:Python write_token_file函数的具体用法?Python write_token_file怎么用?Python write_token_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_token_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_and_get_twitter
def login_and_get_twitter():
# Go to http://twitter.com/apps/new to create an app and get these items
# See also http://dev.twitter.com/pages/oauth_single_token
CREDENTIALS_FILE = './twitter_credentials.txt'
TOKEN_FILE = './twitter_token.oauth' # in the current directory
# try:
(app_name, consumer_key, consumer_secret) = read_credentials_file(CREDENTIALS_FILE)
# except IOError:
# print(TOKEN_FILE + " not found")
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
logging.info('read token from file success')
except IOError as e:
logging.info('read token from file failed, requesting new token')
(oauth_token, oauth_token_secret) = oauth_dance(app_name, consumer_key,
consumer_secret)
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
return twitter.Twitter(domain='api.twitter.com', api_version='1.1',
auth=twitter.oauth.OAuth(oauth_token, oauth_token_secret,
consumer_key, consumer_secret))
示例2: oauth_url_dance
def oauth_url_dance(
consumer_key, consumer_secret, callback_url, oauth_verifier, pre_verify_token_filename, verified_token_filename
):
# Verification happens in two stages...
# 1) If we haven't done a pre-verification yet... Then we get credentials
# from Twitter that will be used to sign our redirect to them, find the
# redirect, and instruct the Javascript that called us to do the redirect.
if not os.path.exists(CREDS_PRE_VERIFIY):
twitter = Twitter(auth=OAuth("", "", consumer_key, consumer_secret), format="", api_version=None)
oauth_token, oauth_token_secret = parse_oauth_tokens(twitter.oauth.request_token(oauth_callback=callback_url))
write_token_file(pre_verify_token_filename, oauth_token, oauth_token_secret)
oauth_url = "https://api.twitter.com/oauth/authorize?" + urllib.urlencode({"oauth_token": oauth_token})
return oauth_url
# 2) We've done pre-verification, hopefully the user has authed us in
# Twitter and we've been redirected to. Check we are and ask for the
# permanent tokens.
oauth_token, oauth_token_secret = read_token_file(CREDS_PRE_VERIFIY)
twitter = Twitter(
auth=OAuth(oauth_token, oauth_token_secret, consumer_key, consumer_secret), format="", api_version=None
)
oauth_token, oauth_token_secret = parse_oauth_tokens(twitter.oauth.access_token(oauth_verifier=oauth_verifier))
write_token_file(verified_token_filename, oauth_token, oauth_token_secret)
return oauth_token, oauth_token_secret
示例3: login
def login():
config = ConfigParser.ConfigParser()
config.readfp(open("twitter.config","rb"))
# Go to http://twitter.com/apps/new to create an app and get these items
# See also http://dev.twitter.com/pages/oauth_single_token
APP_NAME = config.get('account', 'appname')
CONSUMER_KEY = config.get('account', 'consumerkey')
CONSUMER_SECRET = config.get('account', 'consumersecret')
ACCESS_TOKEN = config.get('account', 'accesstoken')
ACCESS_TOKEN_SECRET = config.get('account', 'accesstokensecret')
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
if ACCESS_TOKEN != None and ACCESS_TOKEN_SECRET != None:
oauth_token = ACCESS_TOKEN
oauth_token_secret = ACCESS_TOKEN_SECRET
else:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
示例4: login
def login():
# Go to http://twitter.com/apps/new to create an app and get these items
# See also http://dev.twitter.com/pages/oauth_single_token
APP_NAME = ''
CONSUMER_KEY = '2JRLM23QHyLyBABuqg4tqQ'
CONSUMER_SECRET = 'avpoP356DDKbHtTRiicjKBC01yXqfaI8QCgfZebmjA'
TOKEN_FILE = 'auth/twitter.oauth'
'''
consumer_key = '2JRLM23QHyLyBABuqg4tqQ'
consumer_secret = 'avpoP356DDKbHtTRiicjKBC01yXqfaI8QCgfZebmjA'
access_token = '20692466-4kkQfaO8V0e2cVBDzfYg4EkFdQO9u0CNZLoP8Xma5'
access_token_secret = '0bUGan28R0Dt2f0NIIjA2AcCkNUelANx674aWUH9Oj08f'
'''
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET)
if not os.path.isdir('auth'):
os.mkdir('auth')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
示例5: ipynb_oauth_dance
def ipynb_oauth_dance():
_twitter = twitter.Twitter(auth=twitter.OAuth("", "", CONSUMER_KEY, CONSUMER_SECRET), format="", api_version=None)
oauth_token, oauth_token_secret = parse_oauth_tokens(_twitter.oauth.request_token(oauth_callback=oauth_callback))
# Need to write these interim values out to a file to pick up on the callback
# from Twitter that is handled by the web server in /oauth_helper
write_token_file(OAUTH_FILE, oauth_token, oauth_token_secret)
oauth_url = "http://api.twitter.com/oauth/authorize?oauth_token=" + oauth_token
# Tap the browser's native capabilities to access the web server through a new
# window to get user authorization
display(JS("window.open('%s')" % oauth_url))
示例6: get_twitter_stream
def get_twitter_stream():
try:
(oauth_token, oauth_token_secret)= read_token_file(token_file)
except IOError, e:
(oauth_token, oauth_token_secret)=oauth_dance (app_name, consumer_key, consumer_secret)
if not os.path.isdir(token_path):
os.mkdir(token_path)
write_token_file(token_file, oauth_token, oauth_token_secret)
示例7: oauth_login
def oauth_login(app_name=APP_NAME,consumer_key=CONSUMER_KEY,consumer_secret=CONSUMER_SECRET,token_file='out/twitter_oauth'):
try:
(oauth_token, oauth_token_secret) = read_token_file(token_file)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance('deathcape', consumer_key, consumer_secret)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(token_file,oatuh_token,oauth_token_secret)
print >> sys.stderr, "OAuth Success. Token file stored to", token_file
示例8: oauth_login
def oauth_login(
app_name=APP_NAME, consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, token_file="out/twitter.oauth"
):
try:
(access_token, access_token_secret) = read_token_file(token_file)
except IOError, e:
(access_token, access_token_secret) = oauth_dance(app_name, consumer_key, consumer_secret)
if not os.path.isdir("out"):
os.mkdir("out")
write_token_file(token_file, access_token, access_token_secret)
print >>sys.stderr, "OAuth Success. Token file stored to", token_file
示例9: oauth_helper
def oauth_helper():
oauth_verifier = request.args.get("oauth_verifier")
# Pick back up credentials from ipynb_oauth_dance
oauth_token, oauth_token_secret = read_token_file(OAUTH_FILE)
_twitter = twitter.Twitter(
auth=twitter.OAuth(oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET), format="", api_version=None
)
oauth_token, oauth_token_secret = parse_oauth_tokens(_twitter.oauth.access_token(oauth_verifier=oauth_verifier))
# This web server only needs to service one request, so shut it down
shutdown_after_request = request.environ.get("werkzeug.server.shutdown")
shutdown_after_request()
# Write out the final credentials that can be picked up after the following
# blocking call to webserver.run().
write_token_file(OAUTH_FILE, oauth_token, oauth_token_secret)
return "%s %s written to %s" % (oauth_token, oauth_token_secret, OAUTH_FILE)
示例10: oauth_login
def oauth_login(app_name=APP_NAME,
consumer_key=CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
token_file='auth/twitter.oauth'):
# try to read the token file
try:
(access_token, access_token_secret) = read_token_file(token_file)
except IOError, e: # if it fails, create the token and write it to disk
(access_token, access_token_secret) = oauth_dance(app_name, consumer_key,
consumer_secret)
if not os.path.isdir('auth'):
os.mkdir('auth')
write_token_file(token_file, access_token, access_token_secret)
print >> sys.stderr, "OAuth Success. Token file stored to", token_file
示例11: py_oauth_dance
def py_oauth_dance():
_twitter=twitter.Twitter(auth=twitter.OAuth('','',CONSUMER_KEY, CONSUMET_SECRET), format='', api_version=None)
oauth_token, oauth_token_secret = parse_oauth_tokens(_twitter.oauth.request_token(oauth_callback=oauth_callback))
# Se nececitan escribir estos valores en un archivo para de ahi recojer la
# llamada de Twitter que es manejada del web server en /oauth_helper
write_token_file(OAUTH_FILE,oauth_token, oauth_token_secret)
oauth_url=('http://api.twitter.com/oauth/authorize?oauth_token='+oauth_token)
#Utilizamos el browser para abrir una nueva ventana y asi accesar al web
#server y obtener la autorizacion del usuario
display(JS("windows.open('%s')" % oauth_url))
示例12: login
def login():
# Go to http://twitter.com/apps/new to create an app and get these items
# See also http://dev.twitter.com/pages/oauth_single_token
APP_NAME = "ContatoSalvo"
CONSUMER_KEY = "WwE7cxlLi7FsmyWRKSx17A"
CONSUMER_SECRET = "2YQk2bW98LxcKRCUOicnWWg1tZUukSFwMZqX1MLxT3k"
TOKEN_FILE = "out/twitter.oauth"
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY, CONSUMER_SECRET)
if not os.path.isdir("out"):
os.mkdir("out")
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
示例13: login
def login():
APP_NAME = 'Learning Python - Mining'
CONSUMER_KEY = consumer_key
CONSUMER_SECRET = consumer_secret
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
示例14: login
def login():
APP_NAME = ''
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
TOKEN_FILE = ' '
try:
(oauth_token, oauth_token_secret) = read_token_file('auth/twitter.oauth')
except IOError, e :
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY, CONSUMER_SECRET)
if not os.path.isdir('auth'):
os.mkdir('auth')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
示例15: oauth_login
def oauth_login(app_name='',
consumer_key='',
consumer_secret='',
token_file='out/twitter.oauth'):
try:
(access_token, access_token_secret) = read_token_file(token_file)
except IOError, e:
(access_token, access_token_secret) = oauth_dance(app_name, consumer_key,
consumer_secret)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(token_file, access_token, access_token_secret)
print >> sys.stderr, "OAuth Success. Token file stored to", token_file