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


Python OAuthHandler.get_authorization_url方法代码示例

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


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

示例1: get

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
    def get(self):
        invitationCode = self.request.get('invitation_code')
        if not self.isValidInvitationCode(invitationCode):
            error_output(self, "<html><body>邀请码无效</body></html>", "text/html", 400)
            return
        auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        
        verifier = self.request.get("oauth_verifier").strip()
        twitterId = self.request.get("twitter_id").strip()
        if verifier == "" or twitterId == "":
            authUrl = auth.get_authorization_url()
            success_output(self, page_goto_sina_oauth % \
                {'url':authUrl, 
                 'invitation':invitationCode.encode('UTF-8'),
                 'token':auth.request_token.key, 
                 'secret':auth.request_token.secret})
        else:
            request_token = self.request.get("request_token")
            request_secret = self.request.get("request_secret")
            auth.set_request_token(request_token, request_secret)
            accessToken = auth.get_access_token(verifier)
            binding = SyncBinding.getOrInsertByInvitationCode(invitationCode)
            binding.lastTweetId = None
            binding.twitterId = twitterId
            binding.sinaAccessToken = accessToken.key
            binding.sinaAccessSecret = accessToken.secret
            binding.put()
            success_output(self, '''
<html><body>
<p>Twitter与新浪微博同步绑定成功</p>
<p>如需要修改绑定,请重新访问邀请链接</p>
</body></html>
            ''')
开发者ID:userid,项目名称:TwitterSinaSync,代码行数:35,代码来源:main.py

示例2: init_1st_step

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
 def init_1st_step(self):
     auth = OAuthHandler(APP_KEY, APP_SECRET, '')
     auth_url = auth.get_authorization_url()
     user.update_app('sina', self.email, request_token=auth.request_token.key,
             request_secret=auth.request_token.secret)
     log.debug(repr(user.get(self.email)))
     return auth_url
开发者ID:vincentwyshan,项目名称:VGA,代码行数:9,代码来源:sina.py

示例3: GET

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
    def GET(self):
        access_token=session.get('access_token',None)
        if not access_token:
            auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET,web.ctx.get('homedomain')+'/callback')
            auth_url = auth.get_authorization_url()
            session.request_token=auth.request_token
            web.seeother(auth_url)
        else:
            auth =OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
            auth.access_token=access_token
            api=API(auth)
            user=api.verify_credentials()
            user_timeline=user.timeline(count=10)

            print "current user is ",user.screen_name
            hot_list=get_hot_list()
            for user_tweet in user_timeline:
                try:
                    hot_list.append(tuple([user_tweet.user.screen_name,
                                            user_tweet.mid,
                                            user_tweet.text,
                                            user_tweet.source,
                                            user_tweet.created_at,
                                            None,
                                            None]))
                except AttributeError:
                    #no retweet_statues
                    continue
            return render.index(user.screen_name,user.id,hot_list)
开发者ID:hewigovens,项目名称:tisualize,代码行数:31,代码来源:index.py

示例4: login

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
def login():
    callback = 'http://so2weibo.sinaapp.com/login_callback'

    auth = OAuthHandler(APP_KEY, APP_SECRET, callback)
    # Get request token and login url from the provider
    url = auth.get_authorization_url()
    session['oauth_request_token'] = auth.request_token
    # Redirect user to login
    return redirect(url)
开发者ID:SAEPython,项目名称:Save2Weibo,代码行数:11,代码来源:app.py

示例5: get

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
 def get(self):
     recordtoken = OauthInfo(states="openAccount",service="sina",emailaddr="[email protected]")
     recordtoken.put()
     auth = OAuthHandler(CONSUMER_KEY_SINA, CONSUMER_SECRET_SINA,self.call_back_url+"?UID="+str(recordtoken.key()))
     url = auth.get_authorization_url()
     recordtoken.states = "request_token_got"
     recordtoken.fromOauthToken(auth.request_token)
     recordtoken.put()
     self.redirect(url)
开发者ID:qzhuyan,项目名称:nanomumu,代码行数:11,代码来源:tbotMain.py

示例6: get_access_token

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
def get_access_token(username, password):
    auth = OAuthHandler(APP_KEY, APP_SECRET)
    auth_url = auth.get_authorization_url()
    print "Auth URL: ",auth_url
    veri_obj = GetPIN(auth_url, username, password)   
    verifier = veri_obj.getPIN()
    print "VERIFIER: ",verifier
    if verifier==-1:
        raise Exception("Error Account")
    token = auth.get_access_token(verifier)
    return dict(parse_qsl(str(token)))
开发者ID:chengjun,项目名称:Research,代码行数:13,代码来源:weibo_api.py

示例7: WeiboBackup

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
class WeiboBackup(object):
    """
    新浪微博自动备份.
    """

    def __init__(self):
        self.hdl = OAuthHandler(config.APP_KEY, config.APP_SECRET)
        self.api = None
        self.writer = None
        self.token = {}
        self.auth()

    def auth(self):
        try:
            with open("../" + config.TOKEN_FILE) as f:
                self.token = pickle.load(f)
            self.hdl.setToken(self.token["key"], self.token["secret"])
            self.api = API(self.hdl)
        except Exception as e:
            print e

    def get_auth_url(self):
        return self.hdl.get_authorization_url()

    def get_data(self, screen_name, page):
        count = 200
        while True:
            try:
                res = self.api.user_timeline(screen_name=screen_name, count=count, page=page)
                if len(res) == 0:
                    return page
                else:
                    for status in res:
                        text = status.text
                        retweet = getattr(status, "retweeted_status", False)
                        if retweet:
                            text = text + "//" + retweet.text
                        text = text.encode("utf-8")
                        self.writer.append(text)
                page = page + 1
            except Exception as e:
                print e

    def backup(self, screen_name, filename=""):
        if filename:
            self.writer = Writer(filename)
        else:
            self.writer = []
        page, alert_num = 1, 0
        while alert_num < ALERT_MAX_TIMES:
            page = self.get_data(screen_name, page)
            alert_num += 1
        return self.writer
开发者ID:HIT-Coder,项目名称:SmartWall,代码行数:55,代码来源:run.py

示例8: __init__

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
class SinaClient:
    def __init__(self, key, secret):
        self.auth=OAuthHandler(key,secret)

    def get_auth_url(self):
        return self.auth.get_authorization_url()

    def set_access_token(self,token):
        key,secret=token.split('|')
        self.auth.setToken(key,secret)
        self.api=API(self.auth)

    def get_access_token(self):
        token=self.auth.access_token
        return token.key+'|'+token.secret

    def set_request_token(self,token):
        key,secret=token.split('|')
        self.auth.request_token=oauth.OAuthToken(key,secret)

    def get_request_token(self):
        token=self.auth.request_token
        return token.key+'|'+token.secret

    def set_verifier(self,verifier):
        self.auth.get_access_token(verifier)
        self.api=API(self.auth)

    def send_msg(self,msg,coord=None):
        lat,long=self.get_lat_long(coord)
        msg=msg.encode('utf-8')
        status=self.api.update_status(status=msg,lat=lat,long=long)
        return status

    def send_pic(self,msg,pic,coord=None):
        lat,long=self.get_lat_long(coord)
        msg=msg.encode('utf-8')
        status=self.api.upload(pic,status=msg,lat=lat,long=long)
        
        return status

    def get_timeline(self):
        return self.request(SINA_USER_TIMELINE_URL)

    def get_lat_long(self,coord):
        if not coord:
          return (None,None)

        return map(lambda x:str(x),coord)

    def get_user(self):
        return self.api.verify_credentials()
开发者ID:renorzr,项目名称:twsync,代码行数:54,代码来源:sinaclient.py

示例9: Test

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
class Test(unittest.TestCase):
    
    consumer_key=''
    consumer_secret=''
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception as e:
            print(e)
            return ''
        
    def auth(self):
        
        if len(self.consumer_key) == 0:
            print("Please set consumer_key£¡£¡£¡")
            return
        
        if len(self.consumer_key) == 0:
            print("Please set consumer_secret£¡£¡£¡")
            return
                
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        auth_url = self.auth.get_authorization_url()
        print('Please authorize: ' + auth_url)
        verifier = input('PIN: ').strip()
        self.auth.get_access_token(verifier)
        self.api = API(self.auth)
        
    def setAccessToken(self, key, secret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setAccessToken(key, secret)
        self.api = API(self.auth)
    
    def update(self, message):
        status = self.api.update_status(message)
        self.obj = status
        id = self.getAtt("id")
        text = self.getAtt("text")
        print("update,id="+ str(id) +",text="+ text)
        
    def destroy_status(self, id):
        status = self.api.destroy_status(id)
        self.obj = status
        id = self.getAtt("id")
        text = self.getAtt("text")
        print("update---"+ str(id) +":"+ text)
开发者ID:chengjun,项目名称:Research,代码行数:52,代码来源:oauthUpdate.py

示例10: get_sina_token

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
def get_sina_token():      
    #申请应用时得到的App Key及密码  
    App_key = '3028524014'  
    App_secret = '660eb5d3feacc40d3bba28e0b9dcc50b'  
  
    #授权  
    auth_handler = OAuthHandler(App_key, App_secret)  
    auth_url = auth_handler.get_authorization_url()  
  
    print "Please open this url by your Browser:" + auth_url  
    verifier = raw_input('Please input PIN code get from above url: ').strip()  
      
    #得到token及密码  
    auth_handler.get_access_token(verifier)  
开发者ID:Vitvicky,项目名称:PythonProject,代码行数:16,代码来源:test.py

示例11: do_auth

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
def do_auth():
    auth = OAuthHandler(APP_KEY, APP_SECRET, BACK_URL)
    auth_url = auth.get_authorization_url()
    request_token_key = auth.request_token.key
    request_token_secret = auth.request_token.secret
    auth.set_request_token(request_token_key, request_token_secret)
    webbrowser.open(auth_url)
    verifier = input("Verifier: ").strip()
    access_token = auth.get_access_token(verifier)
    ATK = access_token.key
    ATS = access_token.secret
    auth.setAccessToken(ATK, ATS)
    api = API(auth)
    user = api.verify_credentials()
    logging("[AUTH]: We are uing API from account: [uid = %s, name = %s]" % (user.id, user.screen_name))
    return api
开发者ID:bubargain,项目名称:weibo,代码行数:18,代码来源:weibo_users.py

示例12: sinaapp

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
 def sinaapp(self,app_key,app_secret):
         auth = OAuthHandler(app_key, app_secret)  ##认证
         auth_url = auth.get_authorization_url()    ##返回授权页面链接,用浏览器打开
         #webbrowser.open(auth_url)
         content = self._request(auth_url)[1].read()        
         soup=BeautifulSoup.BeautifulSoup(''.join(content))
         #print content
         pin=soup.span.string   #自动获取pin码
         #print 'Please authorize: ' + auth_url  ##输入获得的Pin码
         #verifier = raw_input('输入您在浏览器页面显示的PIN码: ').strip()
         auth.get_access_token(pin)
         api = API(auth)  #整合函数
         connent=raw_input('What are you want to say?')
         status = api.update_status(status=connent)#发布微博
         print "Send Successed"
         raw_input('Press enter to exit ......')
开发者ID:caozhzh,项目名称:xgoogle,代码行数:18,代码来源:autoweibo.py

示例13: GET

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
 def GET(self):
     access_token=session.get('access_token',None)
     if not access_token:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET,web.ctx.get('homedomain')+'/callback')
         #获得新浪微博的认证url地址
         auth_url = auth.get_authorization_url()
         logger.debug("认证地址为:%s"%auth_url)
         #在session中保存request_token,用于在新浪微博认证通过后换取access_token
         session.request_token=auth.request_token
         web.seeother(auth_url)
     else:
         auth = OAuthHandler(key.CONSUME_KEY, key.CONSUME_SECRET)
         auth.access_token=access_token
         api=API(auth)
         user=api.verify_credentials()
         friends=api.friends()
         return render_template('index.html',friends=friends,user=user)
开发者ID:luo123qwe,项目名称:djproject,代码行数:19,代码来源:sina_twitter.py

示例14: get

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
 def get(self):
     print '123123123'
     verifier = self.get_argument('oauth_verifier', None)
     auth = OAuthHandler(SINA_CONSUME_KEY, SINA_CONSUME_SECRET)
     if not verifier:
         #self.SESSION['goto'] = self.get_argument('to_url', None)
         auth_url = auth.get_authorization_url()+'&oauth_callback='+self.request.protocol+'://'+self.request.host+'/people/auth/'
         self.SESSION['oauth_request_token'] = auth.request_token
         self.redirect(auth_url)
     else:
         request_token = self.SESSION['oauth_request_token']
         del self.SESSION['oauth_request_token']
         auth.set_request_token(request_token.key, request_token.secret)
         access_token = auth.get_access_token(verifier)
         self.SESSION['oauth_access_token'] = access_token
         me = WeiboAPI(auth).me()
         self.after_auth(me)
开发者ID:yimiqisan,项目名称:xiha,代码行数:19,代码来源:user.py

示例15: login

# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import get_authorization_url [as 别名]
def login(request):
    '''get a permanent access token'''
    session = get_current_session()
    if not request.GET.get('oauth_token'):
        '''login and save oauth token'''
        cur_url = _get_absolute_path(request)
        auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, callback = cur_url)
        auth_url = auth.get_authorization_url()
        # 需要保存request_token的信息,留做取access_token用
        session["oauth_token"] = auth.request_token.key
        session["oauth_token_secret"] = auth.request_token.secret
        return http.HttpResponseRedirect(auth_url)
    else:
        ''' Get the access token '''
        oauth_verifier = request.GET.get('oauth_verifier')
        auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        # 从session中取出request_token的信息
        auth.set_request_token(session["oauth_token"], session["oauth_token_secret"])
        auth.get_access_token(oauth_verifier)
        # save access token
        session['access_token_key'] = auth.access_token.key
        session['access_token_secret'] = auth.access_token.secret
        response = shortcuts.redirect('sinaweibo.views.mainPage')
        return response
        
        
    if 0:
        path = os.path.join(os.path.dirname(__file__), "templates/index.html")
        myself = api.get_user(id=1894001933)
        screen_name = myself. __getattribute__("screen_name")
        self.response.out.write(template.render(path,
                {"name": screen_name}))#dir(api.verify_credentials)}))#api.verify_credentials.name}))#screen_name}))

    if 0:
        params = {}
        params['test'] = 'nothing'
        return shortcuts.render_to_response('test.html', params)

    if 0:
        # add GET para and redirect
        response = shortcuts.redirect('sinaweibo.views.mainPage')
        response['Location'] += '?oauth_verifier=%s' % oauth_verifier
        return response
            
开发者ID:zy-sunshine,项目名称:sunblackshineblog,代码行数:45,代码来源:views.py


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