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


Python OAuthHandler.get_access_token方法代码示例

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


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

示例1: get

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_access_token [as 别名]
 def get(self):
     verifier = self.request.GET.get('oauth_verifier')
     
     user = users.get_current_user()
     
     if not user: 
         logging.warning("current user is not logged in")
         self.redirect("/")
     
     logging.info("running callback for user: %s" % user.user_id())
     
     social_users = model.SocialKeysForUsers.all()
     social_users.filter("user_id =",user.user_id())
     
     user_model = social_users.get()
     
     if not user_model == None and user_model.request_token_key and user_model.request_token_secret:
         try:
             auth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET)
             auth.set_request_token(user_model.request_token_key, user_model.request_token_secret)
             
             auth.get_access_token(verifier)
             
             user_model.access_token_key = auth.access_token.key
             user_model.access_token_secret = auth.access_token.secret
             
             api = API(auth)
             api_is_working = api.test()
             
             user_model.shortcut_social_username = api.me().screen_name
             
             user_model.put()
             
             memcache.add("twitter_user:%s" % user.user_id(), user_model.shortcut_social_username, 60)
             
             #self.response.out.write("twitter user name: %s\n" % user_model.shortcut_social_username)
             
             logging.debug("user access tokens have been set")
         
             self.redirect("/")
             
         except TweepError:
             logging.error( "TweepError error API is could not fetch me: %s" % user.user_id())
             
             user_model.access_token_key = None
             user_model.access_token_secret = None
             user_model.put()
             
             self.redirect(URL_STATIC_ERROR_DEFAULT)
         except CapabilityDisabledError:
             logging.error( "Capability Disabled Error could not write for: %s" % user.user_id())
             self.redirect(URL_STATIC_ERROR_DEFAULT)
     
     else: 
         logging.warning("user model is not setup correctly: %s for user % "  % (user_model, user.user_id()))
         self.redirect("/")
开发者ID:twixmit,项目名称:twixmit,代码行数:58,代码来源:main.py

示例2: get_token

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_access_token [as 别名]
    def get_token(self, oauth_token, oauth_token_secret, oauth_verifier):
        auth = OAuthHandler(self._consumer_key, self._consumer_secret)
        auth.request_token = {'oauth_token': oauth_token,
                              'oauth_token_secret': oauth_token_secret}

        auth.get_access_token(oauth_verifier)
        self._access_token = auth.access_token
        self._access_token_secret = auth.access_token_secret
        self._setup_apis()

        return self._access_token, self._access_token_secret
开发者ID:ojos,项目名称:python2.x-library,代码行数:13,代码来源:twitter.py

示例3: get

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_access_token [as 别名]
  def get(self):
    #Set up our twitter auth object
    config = self.app.config['twitter']
    auth = OAuthHandler(config['consumer_key'], config['consumer_secret'], self.request.host_url + '/auth')

    #Check the session state. If it contains a twitter token, 
    #The user has already gone through the authorization step
    tkn = self.session.get('twitter')
    if tkn:
      #If we are on the second phase already
      auth.set_request_token(tkn[0], tkn[1])
      del self.session['twitter']

      verifier = self.request.get('oauth_verifier')
      if verifier:
        #Get the verification code from the URL
        auth.get_access_token(verifier)
        me = API(auth).me()

        #See if we already have a user that has this id.
        results = User.query().filter(User.twitter_id == me.id).fetch()
        if results:
          user = results[0]

          #Make sure all the properties are up-to-date
          user.name = me.name
          user.location = me.location
          user.put()
        else:
          user = User(twitter_id=me.id, name=me.name, location=me.location)
          user.put()
        
        #The user_id should be part of the session
        self.session['user'] = user.key.id()

      self.redirect('/')
    else:
      #Grabs request_tokens and creates a URL for a redirect
      redirect_url = auth.get_authorization_url(signin_with_twitter=True)
      
      #Store the request_token information for the next step
      self.session['twitter'] = (auth.request_token.key, auth.request_token.secret)
      self.redirect(redirect_url)
开发者ID:stephenvisser,项目名称:twitter-auth,代码行数:45,代码来源:handlers.py

示例4: cmd_verify

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_access_token [as 别名]
def cmd_verify(bot, update, args, chat):
    if not chat.twitter_request_token:
        bot.reply(update, "Use /auth command first")
        return
    if len(args) < 1:
        bot.reply(update, "No verifier code specified")
        return
    verifier_code = args[0]
    auth = OAuthHandler(bot.tw.auth.consumer_key, bot.tw.auth.consumer_secret)
    auth.request_token = json.loads(chat.twitter_request_token)
    try:
        auth.get_access_token(verifier_code)
    except TweepError:
        bot.reply(update, "Invalid verifier code. Use /auth again")
        return
    chat.twitter_token = auth.access_token
    chat.twitter_secret = auth.access_token_secret
    chat.save()
    bot.reply(update, "Access token setup complete")
    api = tweepy.API(auth)
    settings = api.get_settings()
    tz_name = settings.get("time_zone", {}).get("tzinfo_name")
    cmd_set_timezone(bot, update, [tz_name])
开发者ID:trinhvv,项目名称:telegram-twitter-forwarder-bot,代码行数:25,代码来源:commands.py

示例5: callback

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_access_token [as 别名]
def callback(request):
    unauthed_token = request.session.get('unauthed_token', None)
    if not unauthed_token:
        return HttpResponse("No un-authed token cookie")
    token = oauth.OAuthToken.from_string(unauthed_token)
    if token.key != request.GET.get('oauth_token', 'no-token'):
        return HttpResponse("Something went wrong! Tokens do not match")
    verifier = request.GET.get('oauth_verifier')
    handler = OAuthHandler(settings.TWITTER_CONSUMER_KEY,
               settings.TWITTER_CONSUMER_SECRET,
               secure=True)
    handler.request_token = token
    access_token = handler.get_access_token(verifier)

    # save token against user
    user = User.objects.get(pk=request.session['user_id'])
    profile = user.get_profile()
    profile.access_token = access_token.key
    profile.access_token_secret = access_token.secret
    profile.save()

    redirect = reverse('fundraiser-page', kwargs={'fundraiser_id': profile.jg_page_id})
    return HttpResponseRedirect(redirect)
开发者ID:gareth-lloyd,项目名称:tweetrace,代码行数:25,代码来源:views.py


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