当前位置: 首页>>代码示例>>Python>>正文


Python OAuthHandler.set_request_token方法代码示例

本文整理汇总了Python中tweepy.OAuthHandler.set_request_token方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthHandler.set_request_token方法的具体用法?Python OAuthHandler.set_request_token怎么用?Python OAuthHandler.set_request_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tweepy.OAuthHandler的用法示例。


在下文中一共展示了OAuthHandler.set_request_token方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: accessToken

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_request_token [as 别名]
	def accessToken(self):
		if self.session.access_token:
			# return the token (TODO: does it expire?)
			auth = OAuthHandler(self.client_id, self.client_secret);
			auth.set_access_token( self.session.access_token.key
								 , self.session.access_token.secret)

			return auth


		if self.session.request_token:
			# Exchange the request token with an authorization token.
			token = self.session.request_token
			self.session.request_token = None

			auth = OAuthHandler( self.client_id, self.client_secret )
			auth.set_request_token(token.key, token.secret)

			try:
				self.session.access_token = auth.get_access_token(self.request.vars.oauth_verifier)
			except tweepy.TweepError:

				print 'Error! Failed to get access token.'

			print self.session.access_token

			return auth

		return None
开发者ID:nulld,项目名称:GeekPartySite,代码行数:31,代码来源:db.py

示例2: callback

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_request_token [as 别名]
def callback(request):
    """
    Receive the Oauth token back from Twitter
    """
    verifier = request.GET.get('oauth_verifier')
    if verifier is None:
        response = HttpResponseRedirect(reverse('experiment_main'))
        return response
    oauth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    token = request.session.get('unauthed_token_twitterexp', None)
    if token is None:
        request.session['auth_error'] = True
        return HttpResponseRedirect(ROOT_URL)

    request.session['auth_error'] = False
    # remove the request token now we don't need it
    request.session.delete('unauthed_token_twitterexp')
    oauth.set_request_token(token[0], token[1])
    # get the access token and store
    try:
        oauth.get_access_token(verifier)
    except TweepError:
        print 'Error, failed to get access token'
        request.session['auth_error'] = True
        return HttpResponseRedirect(ROOT_URL)
    request.session['access_key_twitterexp'] = oauth.access_token.key
    request.session['access_secret_twitterexp'] = oauth.access_token.secret

    api = get_api(request)
    twitter_user = api.me()

    twitter_user = add_or_update_twitter_user(twitter_user)

    experiment_user, user = get_or_add_user(twitter_user)

    user.set_password('')

    user = authenticate(username=twitter_user.twitter_id, password='')
    login(request, user)

    response = HttpResponseRedirect(reverse('experiment_start'))
    return response
开发者ID:martinjc,项目名称:tweetcues-exp,代码行数:44,代码来源:views.py

示例3: twitter_oauth_verify

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_request_token [as 别名]
def twitter_oauth_verify(request):
    redirect_url = reverse('landing')

    request_token_key = request.session.pop('request_token_key', '')
    request_token_secret = request.session.pop('request_token_secret', '')

    handler = OAuthHandler(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
    handler.set_request_token(request_token_key, request_token_secret)

    verifier = request.GET.get('oauth_verifier', '')

    try:
        handler.get_access_token(verifier)
    except TweepError:
        pass
    else:
        user = authenticate(access_token_key=handler.access_token.key, access_token_secret=handler.access_token.secret, consumer_key=settings.CONSUMER_KEY, consumer_secret=settings.CONSUMER_SECRET)
        login(request, user)

        redirect_url = request.session.pop('next', redirect_url)

    return redirect(redirect_url)
开发者ID:beaumartinez,项目名称:rdf,代码行数:24,代码来源:views.py


注:本文中的tweepy.OAuthHandler.set_request_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。