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


Python OAuthHandler.get_authorization_url方法代码示例

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


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

示例1: register

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_authorization_url [as 别名]
def register(request):
    if request.method == 'POST':
        form = FundRaiserRegistration(request.POST)
        if form.is_valid():
            # partially create user, and store unauthed token
            user = _user_from_reg_form(form)
            try:
                profile = _profile_from_reg_form(form, user)
            except ValueError:
                return HttpResponse('that page is already registered')

            request.session['user_id'] = user.pk
            handler = OAuthHandler(settings.TWITTER_CONSUMER_KEY,
                    settings.TWITTER_CONSUMER_SECRET,
                    callback='http://www.justgivingthanks.com/callback/',
                    secure=True)
            auth_url = handler.get_authorization_url()
            request.session['unauthed_token'] = handler.request_token.to_string()
            print 'created user, got token, redirecting to %s' % (auth_url)
            return HttpResponseRedirect(auth_url)
    else:
        form = FundRaiserRegistration() # An unbound form

    return render_to_response('registration.html',
            {'form': form},
            context_instance=RequestContext(request))
开发者ID:gareth-lloyd,项目名称:tweetrace,代码行数:28,代码来源:views.py

示例2: cmd_get_auth_url

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_authorization_url [as 别名]
def cmd_get_auth_url(bot, update, chat):
    auth = OAuthHandler(bot.tw.auth.consumer_key, bot.tw.auth.consumer_secret)
    auth_url = auth.get_authorization_url()
    chat.twitter_request_token = json.dumps(auth.request_token)
    chat.save()
    msg = "go to [this url]({}) and send me your verifier code using /verify code"
    bot.reply(update, msg.format(auth_url),
              parse_mode=telegram.ParseMode.MARKDOWN)
开发者ID:trinhvv,项目名称:telegram-twitter-forwarder-bot,代码行数:10,代码来源:commands.py

示例3: get_auth_url

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_authorization_url [as 别名]
    def get_auth_url(self, params={}, callback_url=None):
        if callback_url is None:
            callback_url = self._callback_url
        callback = '%s?%s' % (callback_url, urllib.urlencode(params))
        auth = OAuthHandler(self._consumer_key, self._consumer_secret, callback)
        url = auth.get_authorization_url()

        return url, auth.request_token
开发者ID:ojos,项目名称:python2.x-library,代码行数:10,代码来源:twitter.py

示例4: get

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_authorization_url [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

示例5: get_template_state_for_user

# 需要导入模块: from tweepy.auth import OAuthHandler [as 别名]
# 或者: from tweepy.auth.OAuthHandler import get_authorization_url [as 别名]
 def get_template_state_for_user(self):
     _template_values = {}
     user = users.get_current_user()
     
     user_model = None
     
     if user:
         logging.info("user: %s",user.nickname)
         social_users = model.SocialKeysForUsers.all()
         social_users.filter("user_id =",user.user_id())
         user_model = social_users.get()
         
         if not user_model == None:
             
             if user_model.access_token_key and user_model.access_token_secret:
                 _template_values["needs_twitter_auth"] = False
                 
                 auth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET)
                 auth.set_access_token(user_model.access_token_key,user_model.access_token_secret)
                 
                 api = API(auth)
                 api_is_working = api.test()
                 
                 if not api_is_working:
                     logging.warning("api is NOT working: %s",api_is_working)
                 
                 try:
                     twitter_user = memcache.get("twitter_user:%s" % user.user_id())
                     
                     if twitter_user == None:
                         twitter_user = api.me()
                         memcache.add("twitter_user:%s" % user.user_id(), twitter_user, 60)
                     
                     logging.info(twitter_user)
                     _template_values["twitter_user"] = twitter_user
                     
                 except TweepError:
                     logging.error( "TweepError error has occured, clearing access tokents")
                     user_model.access_token_key = None
                     user_model.access_token_secret = None
                     user_model.put()
                     
                     _template_values["needs_twitter_auth"] = True
             
             else:
                 _template_values["needs_twitter_auth"] = True
         
         else:
             _template_values["needs_twitter_auth"] = True
             user_model = model.SocialKeysForUsers(user_id=user.user_id())
             user_model.put()
         
     else:
         _template_values["needs_twitter_auth"] = True
         logging.warning("user is empty")
         
         
         
     redirect_url = None
     if _template_values["needs_twitter_auth"] and not user_model == None:
         auth = OAuthHandler(social_keys.TWITTER_CONSUMER_KEY, social_keys.TWITTER_CONSUMER_SECRET,"https://%s/callback" % self.request.host)
         redirect_url = auth.get_authorization_url()
         
         user_model.request_token_key = auth.request_token.key
         user_model.request_token_secret = auth.request_token.secret
         user_model.put()
     
         
     _template_values["redirect_url"] = redirect_url
     
     _template_values["logout_url"] = users.create_logout_url("/")
     _template_values["login_url"] = users.create_login_url("/")
     _template_values["user"] = user
     _template_values["user_model"] = user_model
     
     util = helpers.Util()
     
     _template_values["next_mix_run_time"] = util.get_next_mix_runtime()
     _template_values["current_server_time"] = util.get_current_time_for_show()
     
     return _template_values
开发者ID:twixmit,项目名称:twixmit,代码行数:83,代码来源:main.py


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