本文整理汇总了Python中twitter.oauth.write_token_file函数的典型用法代码示例。如果您正苦于以下问题:Python write_token_file函数的具体用法?Python write_token_file怎么用?Python write_token_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_token_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:Baphomet1105,项目名称:twitMiner-tweet-collector.py,代码行数:25,代码来源:login.py
示例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
开发者ID:scraperwiki,项目名称:twitter-search-tool,代码行数:26,代码来源:twsearch.py
示例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)
开发者ID:jinpeng,项目名称:TwitterHavest,代码行数:29,代码来源:twitter__login.py
示例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)
开发者ID:weikengary,项目名称:CS4242AS3,代码行数:26,代码来源:twitter__login.py
示例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))
开发者ID:paudan,项目名称:python-scripts,代码行数:10,代码来源:production_api.py
示例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)
开发者ID:mrazakhan,项目名称:tweetlog,代码行数:11,代码来源:pt2.py
示例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
开发者ID:deathcape,项目名称:deathcapeProject,代码行数:11,代码来源:friends_followers__get_friends.py
示例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
开发者ID:davidsoloman,项目名称:Recipes-for-Mining-Twitter,代码行数:15,代码来源:recipe__oauth_login.py
示例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)
开发者ID:paudan,项目名称:python-scripts,代码行数:15,代码来源:production_api.py
示例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
开发者ID:benosment,项目名称:twitter-sentiment,代码行数:15,代码来源:oauth.py
示例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))
开发者ID:DeathscytheH,项目名称:MiningSocialWeb,代码行数:16,代码来源:Ejemplo9.2.py
示例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)
开发者ID:giullianomorroni,项目名称:InteligenciaArtificial,代码行数:17,代码来源:twitter_login.py
示例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)
开发者ID:cmeury,项目名称:playground,代码行数:17,代码来源:twitter__login.py
示例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)
开发者ID:fhim50,项目名称:repSch_prototype,代码行数:17,代码来源:twitter_login.py
示例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
开发者ID:carlzhangxuan,项目名称:twitter2,代码行数:17,代码来源:oauthLogin.py
示例16: openAuthPage
def openAuthPage(self):
"""Method to open the web page which gives the PIN code for
authentication. When done, verify the pin code and write the
keys into a local file. The user won't have to do the dance each
time he wants to tweet"""
twitter = Twitter(auth=OAuth('', '', self.CONSUMER_KEY, self.CONSUMER_SECRET), format='', api_version=None)
token, token_secret = self.parseOauthTokens(twitter.oauth.request_token(oauth_callback="oob"))
self.l.debug("Opening authentication URL")
oauth_url = ('https://api.twitter.com/oauth/authorize?oauth_token=' + token)
try:
r = webbrowser.open(oauth_url)
# Sometimes the last command can print some
# crap. Wait a bit so it doesn't mess up the next
# prompt.
time.sleep(2)
if not r:
raise Exception()
except Exception as e:
QtGui.QMessageBox.critical(self, "Authentication", "ChemBrows could not open a web page.\nVisit oauth_url to get the PIN code",
QtGui.QMessageBox.Ok, defaultButton=QtGui.QMessageBox.Ok)
self.l.error("Authentication URL not opened")
self.l.error("openAuthPage: {}".format(e))
self.l.error(traceback.format_exc())
pin = QtGui.QInputDialog.getText(self, "PIN verification", "Enter the PIN to authenticate yourself")
oauth_verifier = pin[0]
twitter = Twitter(auth=OAuth(token, token_secret, self.CONSUMER_KEY, self.CONSUMER_SECRET), format='', api_version=None)
oauth_token, oauth_secret = self.parseOauthTokens(twitter.oauth.access_token(oauth_verifier=oauth_verifier))
self.l.debug("Writing authentication file")
write_token_file(self.MY_TWITTER_CREDS, oauth_token, oauth_secret)
self.twitter = Twitter(auth=OAuth(oauth_token, oauth_secret,
self.CONSUMER_KEY, self.CONSUMER_SECRET))
开发者ID:RKBK,项目名称:ChemBrows,代码行数:46,代码来源:my_twit.py
示例17: login
def login():
#loging to twitter application
APP_NAME = "Finance_Harvest"
CONSUMER_KEY = "Bkvk7JFZmzaVpLjGAWBtxQ"
CONSUMER_SECRET = "y9tugnYJeU8aMNW44o6hwWHC3QVktCYtW3RDm3Mdk"
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
print e.errno, e.strerror
(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)
开发者ID:Tskatom,项目名称:twitter_finance,代码行数:17,代码来源:twitter_login.py
示例18: authenticate
def authenticate(app_name="", consumer_key="", consumer_secret="", token_file="auth/twitter.oauth"):
try:
(access_token, access_token_secret) = read_token_file(token_file)
except IOError:
(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 "OAuth Success. Token file stored to ", token_file
# Connect to Twitter
return twitter.Twitter(
domain="api.twitter.com",
api_version="1.1",
auth=twitter.oauth.OAuth(access_token, access_token_secret, consumer_key, consumer_secret),
)
开发者ID:albusdemens,项目名称:Twitter-mining-project,代码行数:18,代码来源:mining_twitter_beta.py
示例19: oauth_helper
def oauth_helper():
oauth_verifier=request.args.get('oauth_verifier')
#Recojer credenciales de respaldo
oauth_token, oauth_token_secret=read_token_file(OAUTH_FILE)
_twitter=twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMET_SECRET), format='', api_version=None)
oauth_token, oauth_token_secret=parse_oauth_tokens(_twitter.oauth.access_token(oauth_verifier=oauth_verifier))
#Este web server solo necesita servir una peticion, asi que se apaga
shutdown_after_request=request.environ.get('werkzeug.server.shutdown')
shutdown_after_request()
#Se escriben las credenciales
write_token_file(OAUTH_FILE, oauth_token, oauth_token_secret)
return "%s %s se escribio en %s" % (oauth_token, oauth_token_secret, OAUTH_FILE)
开发者ID:DeathscytheH,项目名称:MiningSocialWeb,代码行数:18,代码来源:Ejemplo9.2.py
示例20: 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 = 'bigrams'
CONSUMER_KEY = 'pqVYCCTqqDq3WSrwuAaesw'
CONSUMER_SECRET = 'kvG6OTTvYt6j1rXS34083u9vS0skTSbOCsVImGRWU'
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)
开发者ID:tweettu,项目名称:TweetGraph,代码行数:19,代码来源:oauth_login.py
注:本文中的twitter.oauth.write_token_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论