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


Python VoterManager.retrieve_voter_by_twitter_request_token方法代码示例

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


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

示例1: process_sign_in_response_view

# 需要导入模块: from voter.models import VoterManager [as 别名]
# 或者: from voter.models.VoterManager import retrieve_voter_by_twitter_request_token [as 别名]
def process_sign_in_response_view(request):
    oauth_token = request.GET.get('oauth_token', '')
    oauth_verifier = request.GET.get('oauth_verifier', '')

    if not positive_value_exists(oauth_token) or not positive_value_exists(oauth_verifier):
        # Redirect back to ReactJS so we can display failure message
        return HttpResponseRedirect('http://localhost:3001/twitter/missing_variables')  # TODO Convert to env variable

    voter_manager = VoterManager()
    # Look in the Voter table for a matching request_token, placed by the API endpoint twitterSignInStart
    results = voter_manager.retrieve_voter_by_twitter_request_token(oauth_token)

    if not results['voter_found']:
        # Redirect back to ReactJS so we can display failure message if the token wasn't found
        return HttpResponseRedirect('http://localhost:3001/twitter/token_missing')  # TODO Convert to env variable

    voter = results['voter']

    # Fetch the access token
    try:
        # Set up a tweepy auth handler
        auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
        auth.request_token = {'oauth_token': voter.twitter_request_token,
                              'oauth_token_secret': voter.twitter_request_secret}
        auth.get_access_token(oauth_verifier)

        if not positive_value_exists(auth.access_token) or not positive_value_exists(auth.access_token_secret):
            # Redirect back with error
            return HttpResponseRedirect('http://localhost:3001/twitter/access_token_missing')  # TODO Convert to env var

        voter.twitter_access_token = auth.access_token
        voter.twitter_access_secret = auth.access_token_secret
        voter.save()

        # Next use the access_token and access_secret to retrieve Twitter user info
        api = tweepy.API(auth)
        tweepy_user_object = api.me()

        voter_manager.save_twitter_user_values(voter, tweepy_user_object)

    except tweepy.RateLimitError:
        success = False
        status = 'TWITTER_RATE_LIMIT_ERROR'
    except tweepy.error.TweepError as error_instance:
        success = False
        status = ''
        error_tuple = error_instance.args
        for error_dict in error_tuple:
            for one_error in error_dict:
                status += '[' + one_error['message'] + '] '

    # Redirect back, success
    return HttpResponseRedirect('http://localhost:3001/ballot')  # TODO Convert to env var
开发者ID:eternal44,项目名称:WeVoteServer,代码行数:55,代码来源:views.py


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