本文整理汇总了Python中twython.Twython.verify_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.verify_credentials方法的具体用法?Python Twython.verify_credentials怎么用?Python Twython.verify_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.verify_credentials方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
class TwitterCommands:
"""
Commands that will be executed when a user executes a voice command on the Cocoa application
"""
def __init__(self):
#app key, secret, oauth token, oauth secret. modify
APP_KEY = ''
APP_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_SECRET = ''
self.twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_SECRET)
self.twitter.verify_credentials()
def send_tweet(self, tweet):
self.twitter.update_status(status=tweet)
def update_avatar(self, file_path):
avatar = open(file_path, 'rb')
self.twitter.update_profile_image(image=avatar)
def search_twitter(self, keywords):
search_dict = self.twitter.search(q=keywords, result_type='popular')
for elem in search_dict['statuses']:
print elem['text']
def tweet_image(self, file_path, message):
photo = open(file_path, 'rb')
self.twitter.update_status_with_media(status=message, media=photo)
示例2: uploadTwitter
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def uploadTwitter( random_word):
twitter = Twython(api_key, api_secret,
oauth_token, oauth_token_secret)
twitter.verify_credentials()
#photo = open('C:\Users\Samuel Harper\Documents\GitHub\HourlyArt\HourlyArt\newImage\newImageChanged.jpg', 'rb')
photo = open('HourlyArt/newImage/newImageChanged.jpg', 'rb')
twitter.update_status_with_media(status='HourlyArt Post#' + str(post_number) + ' #generative #generativeart' + ' #' + random_word , media=photo)
示例3: update_status_with
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def update_status_with(oauth, message):
twitter = Twython(oauth['APP_KEY'], oauth['APP_SECRET'], oauth['ACCESS_TOKEN'], oauth['ACCESS_TOKEN_SECRET'])
twitter.verify_credentials()
try:
twitter.update_status(status=message)
except TwythonError as e:
print e
示例4: conexion_twitter
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def conexion_twitter(usuario) :
ob_TokenSocial = get_token_social(usuario, 'Twitter')
ob_app=App.objects.get_or_none(provedor="Twitter")
if ob_TokenSocial:
twitter = Twython ( ob_app.consumer_key , ob_app.consumer_secret , ob_TokenSocial.token , ob_TokenSocial.token_secreto )
try:
twitter.verify_credentials()
except ValueError:
return False
return twitter
else:
return False
示例5: authCredsTwython
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def authCredsTwython(self):
testApi = Twython(self.ck, self.cks, self.at, self.ats)
#Test if the API keys are the developers:
if self.ck in 'UmTtg8DMpMXcgzkbIErSQ':
print colored("WARNING: You're using the developer's Twitter API keys. Did you forget to change the keys in the AuthFile?" , 'yellow')
try:
testApi.verify_credentials()
except twython.exceptions.TwythonAuthError:
print "Twitter authentication failed with the given authenticators. "
else:
print colored("Twitter Authentication seems to be successful", "green")
return testApi
示例6: main
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def main(): ## called via tweet_grabber.py
twitter = Twython(AUTH['app_key'], AUTH['app_secret'], AUTH['oauth_token'], AUTH['oauth_token_secret'])
twitter.verify_credentials() ## what does this do if it fails?
for a, account in enumerate(ACCOUNTS):
log.info("Checking %s..." % account)
try:
timeline = twitter.get_user_timeline(screen_name=account)
except TwythonError as e:
log.error(log.exc(e))
continue
log.info("--> %s has %s total tweets" % (account, len(timeline)))
for t, tweet in enumerate(timeline):
# log.debug(json.dumps(tweet, indent=4, default=lambda x: str(x)))
log.info("Tweet %s:%s" % (a, t))
text = tweet.get('text')
if a == 0 or HASHTAG.lower() in text.lower(): # the first entry in the accounts is the official account -- all tweets are processed
try:
data = {}
dt = datetime.datetime.strptime(tweet.get('created_at'), '%a %b %d %H:%M:%S +0000 %Y')
data['t_utc'] = util.timestamp(dt)
data['Member'] = MEMBERS[a]
data['Handle'] = account
data['Text'] = text
data['Retweet'] = text[:2] == "RT"
data['Url'] = "https://twitter.com/%s/status/%s" % (account, tweet.get('id'))
data['TweetID'] = tweet.get('id')
data['Images'] = []
dup = db.features.find_one({'properties.FeatureType': 'tweet', 'properties.TweetID': data['TweetID']})
if dup is not None:
log.info("--> skipping duplicate tweet")
continue
try:
for image in tweet['extended_entities']['media']:
if image['type'] != "photo":
continue
data['Images'].append({'Url': image['media_url']})
log.info("--> added image %s" % image['media_url'])
except KeyError as e:
pass
log.info("--> %s (RT: %s): %s" % (account, data['Retweet'], data['Text']))
success, value = ingest_data("tweet", data)
if not success:
log.error("--> failed: %s" % value)
else:
log.info("--> %s" % value)
except Exception as e:
log.error(log.exc(e))
continue
else:
log.info("--> skipping unrelated tweet")
示例7: PokeyTwit
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
class PokeyTwit():
def __init__(
self,
lib_path=resource_path(resources.__file__,'twit_lib.txt'),
conf_path='bots.cfg'
):
self.lib_path = lib_path
self.c = c = PokeyConfig(conf_path, PokeyConfig.encoded, True)
try:
print "Initializing twitter bot"
self.twitter = Twython(c.APP_KEY, c.APP_SECRET,
c.OAUTH, c.OAUTH_SECRET)
print "Verifying credentials"
self.twitter.verify_credentials()
while True:
msg = self.get_message().rstrip()
if len(msg)!=0 and len(msg) < 140:
break
print msg
print "length: {}".format(len(msg))
self.twitter.update_status(status=msg)
msg=''
self.exit_status=0
except TwythonError:
self.exit_status=1
def get_timeline(self):
try:
self.timeline = self.twitter.get_home_timeline()
except:
raise
def get_message(self):
# If the lib_path is passed, use this path (does no path validation)
if self.lib_path is None:
# Otherwise, inspect the directory of the calling script and pull from that path
self.lib_path = resource_path(inspect.stack()[-1][1],"twit_lib.txt")
with open(self.lib_path, 'rb') as txt:
twit_list = txt.readlines()
msg = twit_list[random.randint(0,len(twit_list)-1)]
return msg
示例8: conectar
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def conectar(dataUser="andres.txt"):
authFile = open(dataUser).read().splitlines()
# Setting the variables for verificate credentials
APP_KEY = authFile[0]
APP_SECRET = authFile[1]
OAUTH_TOKEN = authFile[2]
OAUTH_TOKEN_SECRET = authFile[3]
#Conectandose a twitter
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
#Verificando credenciales
twitter.verify_credentials()
return twitter
示例9: step2
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def step2(self):
print("Step2")
self.set_header("Access-Control-Allow-Origin",origin)
self.set_header("Access-Control-Allow-Headers",'Authorization')
self.set_header("Access-Control-Allow-Credentials","true")
print("Step2")
oauth_token = self.get_argument("oauth_token")
oauth_verifier = self.get_argument("oauth_verifier")
print("Step 2: oauth_token: " + oauth_token)
print("Step 2: oauth_verifier: " + oauth_verifier)
global OAUTH_TOKEN
global OAUTH_TOKEN_SECRET
global twitter
twitter = Twython(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
final_step = twitter.get_authorized_tokens(oauth_verifier)
OAUTH_TOKEN = final_step['oauth_token']
OAUTH_TOKEN_SECRET = final_step['oauth_token_secret']
print(OAUTH_TOKEN)
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN,OAUTH_TOKEN_SECRET)
screen_name = twitter.verify_credentials()["screen_name"]
twitter.update_status(status='Hello!')
self.write(screen_name)
示例10: index
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def index():
try:
token = r.get("twitter:token")
secret = r.get("twitter:secret")
twitter = Twython(APP_KEY, APP_SECRET, token, secret)
twitter.verify_credentials()
except:
twitter = Twython(APP_KEY, APP_SECRET)
print(request.host)
auth = twitter.get_authentication_tokens(callback_url='http://' + request.host + '/callback')
r.set("twitter:token", auth['oauth_token'])
r.set("twitter:secret", auth['oauth_token_secret'])
return redirect(auth['auth_url'])
return render_template('index.html')
示例11: main
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def main(args):
(_, api_key, api_secret, access_token, access_token_secret) = args
twitter = Twython(
app_key=api_key,
app_secret=api_secret,
oauth_token=access_token,
oauth_token_secret=access_token_secret)
try:
twitter.verify_credentials()
except TwythonError:
# Invalid credentials
return 1
# Okay
return 0
示例12: authenticate
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def authenticate(request):
verifier = request.GET['oauth_verifier']
authToken = request.GET['oauth_token']
tokens = TwitterAuth.objects.get(aToken = authToken)
aToken = authToken
aSecret = tokens.aSecret
tokens.delete()
twitter = Twython(cKey, cSecret,aToken, aSecret)
final_step = twitter.get_authorized_tokens(verifier)
finalToken = final_step['oauth_token']
finalSecret = final_step['oauth_token_secret']
### here we will extract user information from Twitter, and save it to database with tokens.
authorizedTwitter = Twython(cKey, cSecret, finalToken, finalSecret)
userinfo = authorizedTwitter.verify_credentials()
name = userinfo['screen_name']
url = userinfo['profile_image_url']
user = TwitterUser( name = name,\
url = url,\
finalToken = finalToken,\
finalSecret = finalSecret)
try:
user.save()
return index(request, name)
except:
return index(request, name)
示例13: tweet_tack
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def tweet_tack(request):
if not 'tack' in request.POST or not request.POST['tack']:
errors.append('could not locate tack')
this_tack=Tack.objects.get(pk=request.POST['tack'])
this_user = this_tack.author
APP_KEY = "f0wDo5a57mSLYIuaIU4nZA"
APP_SECRET = "XKgYeEng2G1qhVNhH3xae4r5LbDzcGD0QzRQp7nc"
twitter = Twython(APP_KEY, APP_SECRET ,this_user.oauth_token, this_user.oauth_secret)
twitter.verify_credentials()
twitter.get_home_timeline()
if not this_tack.image:
twitter.update_status(status=this_tack.description)
else:
photo = this_tack.image.file
twitter.update_status_with_media(status=this_tack.description, media=photo)
return render(request, 'tackd/corkboard_template.html', {})
示例14: twitter_callback
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def twitter_callback(request):
response = HttpResponse()
context = {}
context['not_logged_in'] = False
oauth_verifier = request.GET['oauth_verifier']
twitter = Twython(
os.environ.get('consumer_key'),
os.environ.get('consumer_secret'),
request.session['request_token']['oauth_token'],
request.session['request_token']['oauth_token_secret'],
)
authorized_tokens = twitter.get_authorized_tokens(oauth_verifier)
request.session['oauth_token'] = authorized_tokens['oauth_token']
request.session['oauth_token_secret'] = authorized_tokens['oauth_token_secret']
twitter = Twython(
os.environ.get('consumer_key'),
os.environ.get('consumer_secret'),
request.session['oauth_token'],
request.session['oauth_token_secret'],
)
request.session['screen_name'] = twitter.verify_credentials()['screen_name']
context['user'] = request.session['screen_name']
rendered = render_to_string('webapp/search.html', context)
response.write(rendered)
return response
示例15: user_login
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verify_credentials [as 别名]
def user_login():
"""
Checks for user tokens.
"""
config = ConfigParser.ConfigParser()
# get keys
app_keys = get_keys(config)
APP_KEY = app_keys[0]
APP_SECRET = app_keys[1]
# get tokens'
app_tokens= get_tokens(config)
OAUTH_TOKEN = app_tokens[0]
OAUTH_TOKEN_SECRET = app_tokens[1]
if OAUTH_TOKEN != '' and OAUTH_TOKEN_SECRET != '':
try:
twitter = Twython(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
print "Login successful."
print "Account: "+twitter.verify_credentials()['screen_name']
except TwythonError as e:
print e
else:
print "Authorization tokens needed."
twitter = create_tokens(config, APP_KEY, APP_SECRET)
return twitter