本文整理汇总了Python中weibopy.auth.OAuthHandler.setToken方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthHandler.setToken方法的具体用法?Python OAuthHandler.setToken怎么用?Python OAuthHandler.setToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weibopy.auth.OAuthHandler
的用法示例。
在下文中一共展示了OAuthHandler.setToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mainPage
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def mainPage(request):
session = get_current_session()
access_token_key = session['access_token_key']
access_token_secret = session['access_token_secret']
oauth_verifier = request.GET.get('oauth_verifier', '')
get_absolute_path(request)
if not access_token_key:
#params['test'] = reverse('sinaweibo.views.login', args=[], kwargs={})#, current_app=context.current_app)
login_url = reverse('sinaweibo.views.login', args=[], kwargs={})
#return shortcuts.render_to_response('test.html', params)
return http.HttpResponseRedirect(login_url)
else:
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.setToken(access_token_key, access_token_secret)
api = API(auth)
#myself = api.get_user(id=1894001933)
#screen_name = myself. __getattribute__('screen_name')
myweibo = []
myweibo_obj = api.user_timeline(count=20, page=1)
for weibo in myweibo_obj:
myweibo.append({'text': weibo.text,
'created_at': weibo.created_at,
'retweeted_status': hasattr(weibo, 'retweeted_status') and weibo.retweeted_status or None,
'source': weibo.source})
wrapper__at(myweibo)
params = {}
params['user'] = api.verify_credentials()
params['result'] = myweibo
template = get_template_uri(appContext, 'weibo.html')
return shortcuts.render_to_response(template, params)
示例2: addFavorite
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def addFavorite(status_id):
auth = OAuthHandler(APP_KEY, APP_SECRET)
# Get currrent user access token from session
access_token = session['oauth_access_token']
auth.setToken(access_token.key, access_token.secret)
api = API(auth)
api.create_favorite(status_id)
示例3: getData
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
class getData():
def __init__(self,flaglt):
APP_KEY = '190802369'
APP_SECRET = 'fb4ce1e3a4b049abb75f104d7a7439d7'
BACK_URL = ''
self.auth = OAuthHandler(APP_KEY,APP_SECRET,BACK_URL)
with open('entry.pickle','rb') as f:
entry = pickle.load(f)
self.key = entry['key']
self.secret = entry['secret']
self.followflag = flaglt[0]
self.friendflag = flaglt[1]
self.weiboflag = flaglt[2]
def getFlagStatus(self):
return (self.followflag,self.friendflag,self.weiboflag)
def searchUser(self,name):
self.auth.setToken(self.key,self.secret)
api = API(self.auth)
try :
user = api.get_user(screen_name=name)
#print user.id
data = (user.screen_name.encode('utf-8'),user.location.encode('utf-8'),user.followers_count,user.friends_count,user.statuses_count,user.profile_image_url)
return data
except Exception ,e:
pass
示例4: WeiboAuthV1
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def WeiboAuthV1(userinfo):
api = None
try:
auth = OAuthHandler(WEIBO_APP_KEY, WEIBO_APP_SECRET)
auth.setToken(userinfo.weibo_access_token, userinfo.weibo_access_token_secret)
api = API(auth)
except Exception as e:
logging.info("WeiboAuth error %s " % e)
return api
示例5: newmessage
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def newmessage(self, message, lat=None, long=None):
log.debug('new message: %s' % message)
auth = OAuthHandler(APP_KEY, APP_SECRET)
info = user.get_app('sina', self.email)
auth.setToken(info['access_token'], info['access_secret'])
api = API(auth)
api.update_status(message)
log.debug('new message done.')
return True
示例6: __init__
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def __init__(self):
# 设定网页应用回调页面(桌面应用设定此变量为空)
BACK_URL = ""
# 验证开发者密钥.
auth = OAuthHandler(APP_KEY, APP_SECRET, BACK_URL)
# 设定用户令牌密钥.
auth.setToken(TOKEN_KEY, TOKEN_SECRET)
# 绑定用户验证信息.
self.api = API(auth)
示例7: updateWeiboStatus
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def updateWeiboStatus(message):
auth = OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.setToken(ACCESS_TOKEN_KEY,ACCESS_TOKEN_SECRET)
api=API(auth)
message = message.encode("utf-8")
status = api.update_status(status=message)
from time import sleep
sleep(5)
示例8: __init__
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def __init__(self,app_key="3146673438",app_secret="f65a02335629c4ff5c4a5314fedfa97f"):
app_key=app_key
app_secret=app_secret
file=open("token","r")
token_key=file.readline()
token_secret=file.readline()
file.close()
auth=OAuthHandler(app_key,app_secret)
auth.setToken(token_key[0:-1],token_secret)
self.api=API(auth)
示例9: api
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def api():
token=get_access_token('w..','c..') #input your weibo id and password here#
atKey =token['oauth_token']
atSecret = token['oauth_token_secret']
from weibopy.error import WeibopError
auth = OAuthHandler(APP_KEY, APP_SECRET)
auth.setToken( atKey, atSecret )
api = API(auth) # bind the authentication information to connect to API
return api
示例10: wrapper
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def wrapper(self, *args, **kwargs):
auth = OAuthHandler(SINA_CONSUME_KEY, SINA_CONSUME_SECRET)
request_token = self.SESSION['oauth_access_token']
if request_token:
auth.setToken(request_token.key, request_token.secret)
api = API(auth)
self.__setattr__('sapi', api)
else:
to_url = '/auth?to_url='+self.request.path
self.redirect(to_url)
return method(self, *args, **kwargs)
示例11: auth
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
def auth(self):
# Check Sina user logged in or not.
self.sina_username = self.request.cookies.get("sina_username")
if self.sina_username:
oauth_key = self.request.cookies.get("oauth_key")
oauth_secret = self.request.cookies.get("oauth_secret")
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.setToken(oauth_key, oauth_secret)
self.api = API(auth)
return True
return False
示例12: sinaAPI
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
class sinaAPI():
def __init__(self, token, tokenSecret):
self.auth = OAuthHandler(consumer_key, consumer_secret)
self.auth.setToken(token, tokenSecret)
self.api = API(self.auth)
def attr(self,obj,key):
try:
return obj.__getattribute__(key)
except Exception,e:
#print e
return ''
示例13: WeiboBackup
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [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
示例14: __init__
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [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()
示例15: myapi
# 需要导入模块: from weibopy.auth import OAuthHandler [as 别名]
# 或者: from weibopy.auth.OAuthHandler import setToken [as 别名]
class myapi():
def __init__(self,username="[email protected]",psw="123456789"):
#self.logfile=log_stream.log_stream("sina_sdk")
global gconsumer_key
global gconsumer_secret
global gtoken
global gtokenSecret
#创建一个opener
self.__cJar=cookielib.CookieJar()
self.__opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.__cJar))
self.__opener.addheaders=[('User-agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')]
urllib2.install_opener(self.__opener)
#创建一个auth对象
self.__auth=OAuthHandler(gconsumer_key,gconsumer_secret)
self.__auth.setToken(gtoken,gtokenSecret)
#创建api对象
self.__api=API(self.__auth)
def __del__(self):
pass
def __get_pin(self,username,psw):
req=urllib2.Request(self.__url)
recvdata=urllib2.urlopen(req).read()
params={
"action":"submit",
"regCallback":"http://api.t.sina.com.cn/oauth/authorize?oauth_token=%s&oauth_callback=none&from=" % self.__oauth_token,
"oauth_token":self.__oauth_token,
"oauth_callback":"none",
"from":"",
"userId":username,
"passwd":psw,
}
req=urllib2.Request("http://api.t.sina.com.cn/oauth/authorize",urllib.urlencode(params))
recvdata=urllib2.urlopen(req).read()
#获得PIN
pin=re.search("<b>.*:[0-9]*<",recvdata).group(0)
pin=pin[pin.find("\x9a")+1:-1]
return pin
def getAtt(self, key):
try:
return self.obj.__getattribute__(key)
except Exception, e:
print e
return ''