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


Python APIClient.get_authorize_url方法代码示例

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


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

示例1: publish

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def publish(msg):


#    print msg
    #print url
    code_obj = Code.objects.first()
    client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
    try:
        if code_obj and code_obj.access_token and code_obj.expires_in:
            pass
        else:
            if not code_obj:
                return redirect(client.get_authorize_url())
            r = client.request_access_token(code_obj.code)
            code_obj.access_token = r.access_token # 新浪返回的token,类似abc123xyz456
            code_obj.expires_in = r.expires_in # token过期的UNIX时间:http://zh.wikipedia.org/wiki/UNIX%E6%97%B6%E9%97%B4
            code_obj.save()

        access_token = code_obj.access_token
        expires_in = code_obj.expires_in

        assert access_token
        print expires_in
        ### TODO: 在此可保存access token
        print "access_token", access_token
        print 'expires_in', expires_in
        client.set_access_token(access_token, expires_in)
        #
        print client.get.statuses__user_timeline()
        print client.post.statuses__update(status=msg)
    except:
        return redirect(client.get_authorize_url())
开发者ID:ZrongH,项目名称:wolfware4,代码行数:34,代码来源:publish.py

示例2: GetClient

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def GetClient(_key, _secret, _redirect_uri, userName, passWord):
    
    client = APIClient(app_key = _key, 
                       app_secret = _secret, 
                       redirect_uri = _redirect_uri)
    
    url = client.get_authorize_url()
    
    print "username:" + userName
    print "password:" + passWord
    print "threads blocked for login now"
    
    #multi-threads synchronize
    theLock.acquire()
    
    webbrowser.open_new(url)
    code = raw_input()
    
    theLock.release()
    #sync finished
    
    print "lock released"
    
    tok_class = client.request_access_token(code)
    token = tok_class.access_token
    expires = tok_class.expires_in
    
    client.set_access_token(token, expires)
    
    return client
开发者ID:B-Rich,项目名称:WSpi,代码行数:32,代码来源:ClientFactory.py

示例3: event_func

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def event_func():
    APP_KEY='2218208544'
    APP_SECRET='956ae245a2f62a11a9eca1d91fbda092'
    CALLBACK_URL='http://cdgir.cumt.edu.cn/ShowCode.aspx'
    client=APIClient(app_key=APP_KEY,app_secret=APP_SECRET,\
                     redirect_uri=CALLBACK_URL)
    url=client.get_authorize_url()
    print url
    webbrowser.open(url)

    code=raw_input("input the code:").strip()
    print code
    r=client.request_access_token(code);
    access_token=r.access_token
    expires_in=r.expires_in
    client.set_access_token(access_token,expires_in)
    val=client.place.pois.show.get(poiid='B2094757D06FA3FD4499')
    text="%s\t%s\t%s\t%s\r\n" % (val.title,val.lon,val.lat,val.address)
    #print poi_result.total_number
    #for val in poi_result:
        #for k, v in val.items():
            #print ("%s : %s" % (k,v))这个是val这个dic的循环遍历
        #text+="%s\t%s\t%s\t%s\r\n" % (val.title,val.lon,val.lat,val.address)#可参考api的json返回示例

    print text
    #print text.encode('utf-8')
    open('log.txt','a').write(text.encode('utf-8'))
开发者ID:kunlbc,项目名称:test,代码行数:29,代码来源:test2.py

示例4: GetCode

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def GetCode(userid, passwd):
    """获取用户code"""
    print 'Get the code...',
    client = APIClient(app_key = APP_KEY, app_secret = APP_SECRET, redirect_uri = CALLBACK_URL)
    referer_url = client.get_authorize_url()
    postdata = {
        "action": "login",
        "client_id": APP_KEY,
        "redirect_uri":CALLBACK_URL,
        "userId": userid,
        "passwd": passwd,
        }
    headers = {
        "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0",
        "Referer":referer_url,
        "Connection":"keep-alive"
    }
    req = urllib2.Request(
        url = AUTH_URL,
        data = urllib.urlencode(postdata),
        headers = headers
    )
    resp = urllib2.urlopen(req)
    print 'success!!!'
    return resp.geturl()[-32:]
开发者ID:505555998,项目名称:weibo_robot,代码行数:27,代码来源:weibo.py

示例5: login

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def login():
    client = APIClient(
        app_key = current_app.config['APP_KEY'],
        app_secret = current_app.config['APP_SECRET'],
        redirect_uri = current_app.config['CALLBACK_URL'])
    url = client.get_authorize_url()
    return redirect(url)
开发者ID:YangZhuoze,项目名称:Zzydaily,代码行数:9,代码来源:views.py

示例6: WebOAuthHandler

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
class WebOAuthHandler():
    """继承自OAuthHandler,提供Web应用方法。"""
    def __init__(self, callback_url, access_token=None, expires_in=None):
        self.client = APIClient(app_key=APP_KEY,
                app_secret=APP_SECRET, redirect_uri=callback_url)
        if access_token is not None:
            logging.info("access_token: %s, expire: %s" % (access_token,
                expires_in))
            self.client.set_access_token(str(access_token), str(expires_in))

    def get_authorize_url(self):
        return self.client.get_authorize_url()

    def update(self, message):
        """添加一条新微博信息"""
        message = message.encode("utf-8")
        self.client.post.statuses__update(status=message)

    def upload(self, filename, message):
        message = message.encode("utf-8")
        f = open(filename)
        self.client.upload.statuses__upload(status=message, pic=f)
        f.close()

    def upload_color(self, message, color_value):
        """上传颜色图片微博"""
        message = message.encode("utf-8")
        data = generate_image_helper.generate_image(color_value)
        logging.info('status: %s, data: %s' % (message, data))
        self.client.upload.statuses__upload(status=message, pic=data)

    def get_user(self, uid):
        user = self.client.get.users__show(uid=uid)
        return user
开发者ID:qhm123,项目名称:icolor,代码行数:36,代码来源:sinat_helper.py

示例7: weibo_auth

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def weibo_auth():
    app_key = current_app.config['APP_KEY']
    app_secret = current_app.config['APP_SECRET']
    callback_url = current_app.config['CALLBACK_URL']
    client = APIClient(app_key=app_key, app_secret=app_secret, redirect_uri=callback_url)
    url = client.get_authorize_url()
    return redirect(url)
开发者ID:jtr109,项目名称:ToDo,代码行数:9,代码来源:views.py

示例8: index

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def index(request):
    """
    跳转到验证页面
    """
    client = APIClient(app_key=APP_KEY,app_secret=APP_SECRET,redirect_uri=CALLBACK_URL)
    auth_url = client.get_authorize_url()
    return HttpResponseRedirect(auth_url)
开发者ID:duoduo3369,项目名称:django-sina-login,代码行数:9,代码来源:sina.py

示例9: get_code

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def get_code(username, password):
    client = APIClient(app_key = APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
    referer_url = client.get_authorize_url()
    conn = httplib.HTTPSConnection('api.weibo.com')
    postdata = urllib.urlencode({"action": "login",
                                 'display':'default',
                                 'withOfficalFlag':0,
                                 'quick_auth':'null',
                                 'withOfficalAccount':'',
                                 'scope':'',
                                 'ticket':'ST-NTgxMjEyMDgyMA==-1451982449-gz-7509E3BB4C2DC05243A15BAE7C54D3A4',
                                 'isLoginSina':'',
                                 'response_type':'code',
                                 'regCallback':'https%3A%2F%2Fapi.weibo.com%2F2%2Foauth2%2Fauthorize%3Fclient_id%3D1163934014%26response_type%3Dcode%26display%3Ddefault%26redirect_uri%3Dhttps%253A%252F%252Fapi.weibo.com%252Foauth2%252Fdefault.html%26from%3D%26with_cookie%3D',
                                 'redirect_uri':CALLBACK_URL,
                                 'client_id':APP_KEY,
                                 'appkey62':'1SgvpQ',
                                 'state':'',
                                 'verifyToken':'null',
                                 'from':'',
                                 'switchLogin':0,
                                 'userId':username,
                                 'passwd':password,
                                 'isLoginSina':0, 
                                 })
    conn.request('POST','/oauth2/authorize',postdata,{'Referer':referer_url, 'Content-Type': 'application/x-www-form-urlencoded'})
    res = conn.getresponse()
    page = res.read()
    #print 'headers===========',res.getheaders()
    print 'msg===========',res.msg
    print 'status===========',res.status
    print 'reason===========',res.reason
    print 'version===========',res.version
开发者ID:huangxy31,项目名称:GetCheckInDataFromWeibo,代码行数:35,代码来源:getCode.py

示例10: GetCode

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def GetCode(userid,passwd):
    client = APIClient(app_key = APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
    referer_url = client.get_authorize_url()
    postdata = {
        "action": "login",
        "client_id": APP_KEY,
        "redirect_uri":CALLBACK_URL,
        "userId": userid,
        "passwd": passwd,
        }

    headers = {
        "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36",
        "Referer":referer_url,
        "Connection":"keep-alive"
    }

    req  = urllib2.Request(
        url = AUTH_URL,
        data = urllib.urlencode(postdata),
        headers = headers
    )

    resp = urllib2.urlopen(req)
    print resp.read()
    return resp.geturl()[-32:]
开发者ID:sexroute,项目名称:Python,代码行数:28,代码来源:oauth2.py

示例11: authorize

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def authorize(user_password, parameters):
    """Get Auth2.0 from weibo.
    """
    # http://jas0n.me/2014/12/19/weibo_robot/

    USERID = '[email protected]' #微博登陆邮箱
    PASSWORD = user_password #微博登陆密码

    client = APIClient(app_key=parameters['APP_KEY'], 
                       app_secret=parameters['APP_SECRET'], 
                       redirect_uri=parameters['CALLBACK_URL'])
    referer_url = client.get_authorize_url()
    # print('referer_url: %s' % referer_url)

    # 获取URL参数code:
    # https://api.weibo.com/oauth2/authorize?redirect_uri=http%3A//frank-the-obscure.me/&response_type=code&client_id=1512985854

    code = '0b9e70a77bae860c34c02fbffbfd8c00' # manually got code
    #client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET,
    #                   redirect_uri=CALLBACK_URL)
    r = client.request_access_token(code)
    access_token = r.access_token # 新浪返回的token,类似abc123xyz456
    expires_in = r.expires_in # token过期的UNIX时间:http://zh.wikipedia.org/wiki/UNIX%E6%97%B6%E9%97%B4
    print('token:', access_token)
    print('expires in', expires_in)
    client.set_access_token(access_token, expires_in)
开发者ID:mofhu,项目名称:pkuairquality,代码行数:28,代码来源:weibo_post.py

示例12: main

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def main(request):

    client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
    url = client.get_authorize_url()
    t = get_template('FreeJoinapp/index.html')
    html = t.render(Context({'WeiboUrl': url}))
    return HttpResponse(html)
开发者ID:zhangshijie,项目名称:FreeJoin,代码行数:9,代码来源:views.py

示例13: authorize

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
    def authorize(self, username, password):
        try:
            client = APIClient(app_key=const.APP_KEY, app_secret=const.APP_SECRET,
                               redirect_uri=const.CALLBACK_URL)

            # Step 1: Get the authorize url from Sina
            authorize_url = client.get_authorize_url()

            # Step 2: Send the authorize info to Sina and get the authorize_code
            authorize_code = authorize(authorize_url, username, password)
            if not authorize_code:
                self.loginReturn.emit(self.PASSWORD_ERROR)
                return

            # Step 3: Get the access token by authorize_code
            r = client.request_access_token(authorize_code)

            # Step 4: Setup the access token of SDK
            client.set_access_token(r.access_token, r.expires_in)
            const.client = client
            self.loginReturn.emit(self.SUCCESS)
            return
        except:
            self.loginReturn.emit(self.NETWORK_ERROR)
            return
开发者ID:lxg19880914,项目名称:WeCase,代码行数:27,代码来源:LoginWindow.py

示例14: getAccess

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
def getAccess():
    ACCOUNT = "[email protected]"
    PASSWORD = "aiai2012"
    
    # get configure from file
    accessFile = open( path+"/accessKey.conf", "r" )
    values = accessFile.readlines()
    accessFile.close()

    accessKeys = []
    for value in values:
        accessKeys.append( value.strip() )

    # get the weibo authorization
    try:
        APP_KEY = accessKeys[ 0 ]
        APP_SECRET = accessKeys[ 1 ]
        CALLBACK_URL = accessKeys[ 2 ]

        client = APIClient( app_key = APP_KEY, app_secret = APP_SECRET, redirect_uri = CALLBACK_URL )
        # webbrowser.open_new( client.get_authorize_url() )
        url = client.get_authorize_url()
        conn = httplib.HTTPSConnection('api.weibo.com')
        postdata = urllib.urlencode({'client_id':APP_KEY,'response_type':'code','redirect_uri':CALLBACK_URL,'action':'submit','userId':ACCOUNT,'passwd':PASSWORD,'isLoginSina':0,'from':'','regCallback':'','state':'','ticket':'','withOfficalFlag':0})
        conn.request('POST','/oauth2/authorize',postdata,{'Referer':url,'Content-Type': 'application/x-www-form-urlencoded'})
        res = conn.getresponse()
        location = res.getheader('location')
        code = location.split('=')[1]
        conn.close()
        
        r = client.request_access_token( code )
        client.set_access_token( r.access_token, r.expires_in )
        return client
    except:
        print sys.exc_info()[0], sys.exc_info()[1]
开发者ID:Lhfcws,项目名称:ai_hw,代码行数:37,代码来源:getAccess.py

示例15: accessToken_get

# 需要导入模块: from weibo import APIClient [as 别名]
# 或者: from weibo.APIClient import get_authorize_url [as 别名]
 def accessToken_get(self):
     APP_KEY = '1690375172'
     APP_SECRET = 'e09cff8b33bd34426831fbf63caf00ca'
     CALLBACK_URL = 'http://weibo.com/itgeeks'
     ACCOUNT = '[email protected]'
     PASSWORD = 'huiyuanai'
     
     #for getting the authorize url
     client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
     url = client.get_authorize_url()
     print url
     conn = httplib.HTTPSConnection('api.weibo.com')
     postdata = urllib.urlencode({'client_id':APP_KEY,'response_type':'code','redirect_uri':CALLBACK_URL,'action':'submit','userId':ACCOUNT,
                                       'passwd':PASSWORD,'isLoginSina':0,'from':'','regCallback':'','state':'','ticket':'','withOfficalFlag':0})
     conn.request('POST','/oauth2/authorize',postdata,{'Referer':url,'Content-Type': 'application/x-www-form-urlencoded'})
     res = conn.getresponse()
     print 'headers===========',res.getheaders()
     print 'msg===========',res.msg
     print 'status===========',res.status
     print 'reason===========',res.reason
     print 'version===========',res.version
     location = res.getheader('location')
     print location
     code = location.split('=')[1]
     conn.close()
     
     r = client.request_access_token(code)
     access_token = r.access_token # The token return by sina
     expires_in = r.expires_in
     
     print "access_token=" ,access_token, "expires_in=" ,expires_in
     
     #save the access token
     client.set_access_token(access_token, expires_in)
     return client
开发者ID:whzhcahzxh,项目名称:sentimentAnalysis,代码行数:37,代码来源:getAccessToken.py


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