本文整理汇总了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())
示例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
示例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'))
示例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:]
示例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)
示例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
示例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)
示例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)
示例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
示例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:]
示例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)
示例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)
示例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
示例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]
示例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