本文整理汇总了Python中twython.Twython.verifyCredentials方法的典型用法代码示例。如果您正苦于以下问题:Python Twython.verifyCredentials方法的具体用法?Python Twython.verifyCredentials怎么用?Python Twython.verifyCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twython.Twython
的用法示例。
在下文中一共展示了Twython.verifyCredentials方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verifyCredentials [as 别名]
def run(self):
pp = pprint.PrettyPrinter(depth=6)
api = Twython(app_key=options.consumer_key,
app_secret=options.consumer_secret,
oauth_token=options.access_token_key,
oauth_token_secret=options.access_token_secret)
#do_simulate = True
do_simulate = False
current_user = { 'id_str' : '1041065317' }
if not do_simulate:
current_user = api.verifyCredentials()
pp.pprint(current_user)
fortuneComposer = FortuneComposer()
followController = follow.FollowController([ follow.FollowComposer(current_user) ], current_user=current_user)
retweetController = retweet.RetweetController([ retweet.RetweetComposer() ], current_user=current_user)
replyController = reply.ReplyController([ fortuneComposer ], current_user=current_user)
postController = post.PostController([ fortuneComposer ], current_user=current_user)
default_time_to_sleep = 1
if do_simulate:
default_time_to_sleep = 1
user_stream = stream.Stream(api,
{ 'endpoint' : 'https://userstream.twitter.com/1.1/user.json', 'track' : 'bucketobytes' },
[ followController, retweetController, replyController, postController ],
default_time_to_sleep,
do_simulate)
user_stream.connectStream()
示例2: logged_in
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verifyCredentials [as 别名]
def logged_in(request):
user = request.user.twitterprofile
twitter = Twython(
twitter_token= settings.TWITTER_KEY,
twitter_secret = settings.TWITTER_SECRET,
oauth_token = user.oauth_token,
oauth_token_secret = user.oauth_secret
)
user_data = twitter.verifyCredentials()
return render_to_response('logged_in.html', {'user_data': user_data})
示例3: authenticate
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verifyCredentials [as 别名]
def authenticate(self, oauth_token=None, oauth_secret=None):
'''
Authenticates the oauth credentials by requesting user information
from twitter.
'''
api = Twython(
twitter_token = CONSUMER_KEY,
twitter_secret = CONSUMER_SECRET,
oauth_token = oauth_token,
oauth_token_secret = oauth_secret
)
twitter_user = api.verifyCredentials()
username = '@'.join([str(twitter_user['id']), 'twitter'])
try:
user = User.objects.get(username=username)
except:
# User wasn't been registered through this backend
return None
return user
示例4: twitter_return
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verifyCredentials [as 别名]
def twitter_return(request, window_type):
"""
A user gets redirected here after hitting Twitter and authorizing your
app to use their data.
This is the view that stores the tokens you want
for querying data. Pay attention to this.
"""
# Now that we've got the magic tokens back from Twitter, we need to exchange
# for permanent ones and store them...
api = Twython(
twitter_token = CONSUMER_KEY,
twitter_secret = CONSUMER_SECRET,
oauth_token = request.session['request_token']['oauth_token'],
oauth_token_secret = request.session['request_token']['oauth_token_secret']
)
# Retrieve the tokens we want...
twitter_tokens = api.get_authorized_tokens()
api = get_authorized_twython(twitter_tokens)
username = '@'.join([str(twitter_tokens['user_id']), 'twitter'])
request.session['twitter_tokens'] = twitter_tokens
# No need to call authorize because of get_authorized_tokens()
# Probable bug - need to fix when TwitterUserProfile already exists without
# user having logged in.
try:
user = User.objects.get(username=username)
up = UserProfile.objects.get(user=user)
twitter_user = TwitterUserProfile.objects.get(user=up)
except:
# Create User, UserProfile, TwitterUserProfile
twitter_user = api.verifyCredentials()
if 'error' in twitter_user:
del request.session['access_token']
del request.session['request_token']
return HttpResponse("Unable to authenticate you!")
name = twitter_user['name'].split()
if(len(name) > 0):
first_name = name[0]
else:
first_name = "Unknown User"
if(len(name) > 1):
last_name = name[1]
else:
last_name = ""
user = User(username=username, first_name=first_name, last_name=last_name)
user.set_unusable_password()
user.save()
up = UserProfile(user=user)
# whale = Whale(species=WhaleSpecies.getDefaultSpecies())
# whale.save()
# up.whale = whale
up.save()
try:
tp = TwitterUserProfile.objects.get(user_id=user.id)
except TwitterUserProfile.DoesNotExist:
tp = TwitterUserProfile()
tp.__dict__.update(twitter_user)
tp.user = up
tp.oauth_token = twitter_tokens['oauth_token']
tp.oauth_secret = twitter_tokens['oauth_token_secret']
tp.active_classifier = DEFAULT_CLASSIFIER
tp.classifier_version = DEFAULT_CLASSIFIER_VERSION
tp.save()
# Hack so don't have to call authenticate
user.backend = 'twitter.auth.TwitterAuthentication'
login(request, user)
if window_type == 'popup':
return render_to_response("twitter/twitter_return.html", {'twitter_user': twitter_user},
context_instance=RequestContext(request))
elif window_type == 'api':
return HttpResponse()
else:
return HttpResponseRedirect("/")
示例5: exit
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verifyCredentials [as 别名]
print "No consumer key"
exit()
pp = pprint.PrettyPrinter(depth=6)
api = Twython(app_key=options.consumer_key,
app_secret=options.consumer_secret,
oauth_token=options.access_token_key,
oauth_token_secret=options.access_token_secret)
rates = api.getRateLimitStatus()
remaining_hits = rates['remaining_hits']
rate_reset = rates['reset_time_in_seconds']
print 'Rate limit: ' + str(remaining_hits)
current_user = api.verifyCredentials()
fortunes = open('fortunes').read().split('\n%\n')
if len(fortunes) == 0:
exit()
for fortune in fortunes:
if len(fortune) > 140:
fortunes.remove(fortune)
def followed(follow):
source_id = follow['source']['id_str']
target_id = follow['target']['id_str']
new_id = ""
if source_id != current_user['id_str']:
new_id = source_id
示例6: __init__
# 需要导入模块: from twython import Twython [as 别名]
# 或者: from twython.Twython import verifyCredentials [as 别名]
class TwitterServer:
def __init__(self):
# You can choose to latch tweets topics
latch = False
if rospy.has_param('latch'):
latch = rospy.get_param('latch')
# In case you can't direct message a user, replace DM with a public
# '@user text' tweet.
self.replace_dm = False
if rospy.has_param('replace_dm'):
self.replace_dm = rospy.get_param('replace_dm')
# Publish mentions, home timeline and direct messages
self.pub_home = rospy.Publisher('home_timeline', Tweets, latch = latch)
self.pub_mentions = rospy.Publisher('mentions', Tweets, latch = latch)
self.pub_dm = rospy.Publisher('direct_messages', Tweets, latch = latch)
# Create a bridge for images conversions
self.bridge = CvBridge()
# Last Tweets (init values are twitter API default)
self.last_mention = 12345
self.last_timeline = 12345
self.last_dm = 12345
oauth_token = None
oauth_token_secret = None
# Get OAuth info through parameter server
if rospy.has_param('~token'):
oauth_token = rospy.get_param('~token')
if rospy.has_param('~token_secret'):
oauth_token_secret = rospy.get_param('~token_secret')
# OAuth token creation (see get_access_token.py from python-twitter)
if oauth_token is None or oauth_token_secret is None:
rospy.loginfo("No OAuth information given, trying to create...")
t = Twython( app_key = 'HbAfkrfiw0s7Es4TVrpSuw',
app_secret = 'oIjEOsEbHprUa7EOi3Mo8rNBdQlHjTGPEpGrItZj8c')
# Get AUth URL. Use for login for security,
url = t.get_authentication_tokens()
t = Twython(app_key = 'HbAfkrfiw0s7Es4TVrpSuw',
app_secret = 'oIjEOsEbHprUa7EOi3Mo8rNBdQlHjTGPEpGrItZj8c',
oauth_token = url['oauth_token'],
oauth_token_secret = url['oauth_token_secret'])
# Open web browser on given url
import webbrowser
webbrowser.open( url['auth_url'] )
rospy.logwarn("Log your twitter, allow TwitROS and copy pincode.")
# Wait to avoid webbrowser to corrupt raw_input
rospy.sleep( rospy.Duration( 5 ) )
# Enter pincode
pincode = raw_input('Pincode: ').strip()
auth_props = t.get_authorized_tokens(oauth_verifier = pincode)
oauth_token = auth_props['oauth_token']
oauth_token_secret = auth_props['oauth_token_secret']
rospy.loginfo("Using the following parameters for oauth: "
+ 'key: [{key}], '.format(key = oauth_token)
+ 'secret: [{secret}]'.format(secret = oauth_token_secret))
# Consumer key and secret are specific to this App.
# Access token are given through OAuth for those consumer params
rospy.loginfo('Trying to log into Twitter API...')
# Twython
self.t = Twython(app_key = 'HbAfkrfiw0s7Es4TVrpSuw',
app_secret = 'oIjEOsEbHprUa7EOi3Mo8rNBdQlHjTGPEpGrItZj8c',
oauth_token = oauth_token,
oauth_token_secret = oauth_token_secret)
result = self.t.verifyCredentials();
rospy.loginfo("Twitter connected as {name} (@{user})!"
.format(name = result['name'], user = result['screen_name']))
# Stock screen name (used to show friendships)
self.name = result['screen_name']
# Advertise services
self.post = rospy.Service('post_tweet', Post, self.post_cb)
self.retweet = rospy.Service('retweet', Id, self.retweet_cb)
self.follow = rospy.Service('follow', User, self.follow_cb)
self.unfollow = rospy.Service('unfollow', User, self.unfollow_cb)
self.post_dm = rospy.Service('post_dm', DirectMessage, self.post_dm_cb)
self.destroy = rospy.Service('destroy_dm', Id, self.destroy_cb)
self.timeline = rospy.Service(
'user_timeline', Timeline, self.user_timeline_cb)
#.........这里部分代码省略.........