本文整理汇总了Python中twitter.oauth_dance函数的典型用法代码示例。如果您正苦于以下问题:Python oauth_dance函数的具体用法?Python oauth_dance怎么用?Python oauth_dance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了oauth_dance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: twitter_init
def twitter_init():
try:
config_settings["twitter_creds_file"] = os.path.abspath(
os.path.expanduser(config_settings["twitter_creds_file"])
)
if not os.path.exists(config_settings["twitter_creds_file"]):
twitter.oauth_dance(
"fuzzer_stats",
config_settings["twitter_consumer_key"],
config_settings["twitter_consumer_secret"],
config_settings["twitter_creds_file"],
)
oauth_token, oauth_secret = twitter.read_token_file(config_settings["twitter_creds_file"])
twitter_instance = twitter.Twitter(
auth=twitter.OAuth(
oauth_token,
oauth_secret,
config_settings["twitter_consumer_key"],
config_settings["twitter_consumer_secret"],
)
)
return twitter_instance
except (twitter.TwitterHTTPError, URLError):
print_err("Network error, twitter login failed! Check your connection!")
sys.exit(1)
示例2: tweet
def tweet(entry, conf, dryrun=False):
"""Send a tweet with the title, link and tags from an entry. The first time you
need to authorize Acrylamid but than it works without any interaction."""
key = "6k00FRe6w4SZfqEzzzyZVA"
secret = "fzRfQcqQX4gcZziyLeoI5wSbnFb7GGj2oEh10hnjPUo"
creds = os.path.expanduser('~/.twitter_oauth')
if not os.path.exists(creds):
twitter.oauth_dance("Acrylamid", key, secret, creds)
oauth_token, oauth_token_secret = twitter.read_token_file(creds)
t = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_token_secret, key, secret))
tweet = u"New Blog Entry: {0} {1} {2}".format(entry.title,
helpers.joinurl(conf['www_root'], entry.permalink),
' '.join([u'#' + helpers.safeslug(tag) for tag in entry.tags]))
print(' ', bold(blue("tweet ")), end='')
print('\n'.join(wrap(tweet.encode('utf8'), subsequent_indent=' '*13)))
if not dryrun:
try:
t.statuses.update(status=tweet.encode('utf8'))
except twitter.api.TwitterError as e:
try:
log.warn("%s" % json.loads(e.response_data)['error'])
except (ValueError, TypeError):
log.warn("Twitter: something went wrong...")
示例3: __init__
def __init__ (self, ckey, csecret, token_file, user_name=""):
if not os.path.exists(token_file):
twitter.oauth_dance(user_name, ckey, csecret, token_file)
self.oauth_token, self.oauth_token_secret = twitter.read_token_file(token_file)
self.handle = twitter.Twitter(
auth=twitter.OAuth(self.oauth_token, self.oauth_token_secret,
ckey, csecret))
示例4: setup_twitter
def setup_twitter(consumer_key, consumer_secret, credentials_file):
# Authenticate to twitter using OAuth
if not os.path.exists(credentials_file):
twitter.oauth_dance("Tweet to Door Sign Converter", consumer_key,
consumer_secret, credentials_file)
oauth_token, oauth_secret = twitter.read_token_file(credentials_file)
t = twitter.Twitter(auth=twitter.OAuth(
oauth_token, oauth_secret, consumer_key, consumer_secret))
return t
示例5: oauth_login
def oauth_login(consumer_key, consumer_secret, access_token, access_token_secret):
if not access_token or not access_token_secret:
oauth_file = './twitter_oauth'
if not os.path.exists(oauth_file):
twitter.oauth_dance("App", consumer_key, consumer_secret, oauth_file)
access_token, access_token_secret = twitter.read_token_file(oauth_file)
auth = twitter.oauth.OAuth(access_token, access_token_secret,
consumer_key, consumer_secret)
return twitter.Twitter(auth=auth)
示例6: get_twitter
def get_twitter():
MY_TWITTER_CREDS = os.path.join(os.path.dirname(__file__), '.clocktweeter_credentials')
if not os.path.exists(MY_TWITTER_CREDS):
twitter.oauth_dance("Trinity clock tweeter", CONSUMER_KEY,
CONSUMER_SECRET, MY_TWITTER_CREDS)
oauth_token, oauth_secret = twitter.read_token_file(MY_TWITTER_CREDS)
t = twitter.Twitter(auth=twitter.OAuth(
oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
return t
示例7: get_twitter_client
def get_twitter_client():
CONSUMER_KEY = 'mDW8dNVXrioYiSjse9hneaDGy'
CONSUMER_SECRET = 'jg0A2CcHaVSBWfsOqhgABUxQoZUx7sstEk9NSVUbVphkGJr1Zb'
oauth_filename = 'credentials'
if not os.path.exists(oauth_filename):
twitter.oauth_dance("ruukku", CONSUMER_KEY, CONSUMER_SECRET, oauth_filename)
oauth_token, oauth_secret = twitter.read_token_file(oauth_filename)
auth = twitter.OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)
return twitter.Twitter(auth=auth)
示例8: tweet
def tweet(self, app_name, version):
MY_TWITTER_CREDS = os.path.expanduser('~/.twitter_oauth')
CONSUMER_KEY, CONSUMER_SECRET = self.load_app_keys()
if not os.path.exists(MY_TWITTER_CREDS):
twitter.oauth_dance("autopkgsays", CONSUMER_KEY, CONSUMER_SECRET,
MY_TWITTER_CREDS)
oauth_token, oauth_secret = twitter.read_token_file(MY_TWITTER_CREDS)
twitter_instance = twitter.Twitter(auth=twitter.OAuth(
oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
# Now work with Twitter
twitter_instance.statuses.update(status="%s version %s has been released" % (app_name, version))
示例9: __init__
def __init__(self):
if not file.exists(OAUTH_TOKEN_FILE):
oauth_dance("mpvshots",
CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN_FILE)
oauth_token, oauth_secret = read_token_file(OAUTH_TOKEN_FILE)
oauth = OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)
self._twitter = Twitter(auth=oauth)
self._upload = Twitter(domain="upload.twitter.com", auth=oauth)
示例10: connect
def connect():
global t
# Twitter credentials
CONSUMER_KEY = "JEdRRoDsfwzCtupkir4ivQ"
CONSUMER_SECRET = "PAbSSmzQxbcnkYYH2vQpKVSq2yPARfKm0Yl6DrLc"
MY_TWITTER_CREDS = os.path.expanduser("~/.my_app_credentials")
if not os.path.exists(MY_TWITTER_CREDS):
oauth_dance("Semeval sentiment analysis", CONSUMER_KEY, CONSUMER_SECRET, MY_TWITTER_CREDS)
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS)
t = Twitter(auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
示例11: authenticate
def authenticate(self):
""" Authenticates with twitter app and returns a Twitter object. """
if not os.path.exists(self.TWITTER_CREDS):
oauth_dance(
self.APP_NAME,
self.CONSUMER_KEY,
self._consumer_secret,
self.TWITTER_CREDS
)
oauth_token, oauth_secret = read_token_file(self.TWITTER_CREDS)
return Twitter(auth=OAuth(
oauth_token, oauth_secret, self.CONSUMER_KEY, self._consumer_secret
))
示例12: send_twitter
def send_twitter(APP_NAME, CONSUMER_KEY, CONSUMER_SECRET, tweet):
MY_TWITTER_CREDS = os.path.expanduser('./twitter_id')
if not os.path.exists(MY_TWITTER_CREDS):
twitter.oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET, MY_TWITTER_CREDS)
print(em('saved access token') + 'at' + MY_TWITTER_CREDS)
oauth_token, oauth_secret = twitter.read_token_file(MY_TWITTER_CREDS)
tw = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_secret,
CONSUMER_KEY, CONSUMER_SECRET))
tw.statuses.update(status=tweet)
print('Tweeted.')
示例13: __init__
def __init__(self, connect=True):
# Offline?
if connect:
# Twitter credentials
CONSUMER_KEY='JEdRRoDsfwzCtupkir4ivQ'
CONSUMER_SECRET='PAbSSmzQxbcnkYYH2vQpKVSq2yPARfKm0Yl6DrLc'
MY_TWITTER_CREDS = os.path.expanduser('~/.my_app_credentials')
if not os.path.exists(MY_TWITTER_CREDS):
oauth_dance("Semeval sentiment analysis", CONSUMER_KEY, CONSUMER_SECRET, MY_TWITTER_CREDS)
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS)
self.t = Twitter(auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
示例14: __init__
def __init__(self, autogen=True, markovdb=os.path.expanduser("~/markov"), twcreds=os.path.expanduser("~/.michiov_twitter_credentials"),twappcreds=os.path.expanduser("~/.michiov_twitter_appdata")):
self.mc = MarkovChain(markovdb)
self.reload()
if not os.path.exists(twappcreds):
print("Lack of app creds")
sys.exit(1)
twcons = json.loads(open(twappcreds).read())
conskey = twcons['key']
conssec = twcons['secret']
while not os.path.exists(twcreds):
twitter.oauth_dance("MPRZ Tech Labs", conskey, conssec, twcreds)
oauth_token, oauth_secret = twitter.read_token_file(twcreds)
self.t = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_secret, conskey, conssec))
示例15: connect_twitter
def connect_twitter():
"""Initialize connection to Twitter"""
# authenticate
creds = os.path.expanduser('~/.tweets2sql-oauth')
CONSUMER_KEY = 'mikYMFxbLhD1TAhaztCshA'
CONSUMER_SECRET = 'Ys9VHBWLS5fX4cFnDHSVac52fl388JV19yJz1WMss'
if not os.path.exists(creds):
twitter.oauth_dance("tweets2sql", CONSUMER_KEY, CONSUMER_SECRET, creds)
oauth_token, oauth_secret = twitter.read_token_file(creds)
auth = twitter.OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)
# connect
return twitter.Twitter(domain='api.twitter.com', auth=auth, api_version = '1.1')