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


Python OAuthHandler.setToken方法代码示例

本文整理汇总了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)
开发者ID:zy-sunshine,项目名称:sunblackshineblog,代码行数:34,代码来源:views.py

示例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)
开发者ID:SAEPython,项目名称:Save2Weibo,代码行数:9,代码来源:app.py

示例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
开发者ID:shch,项目名称:weibo,代码行数:31,代码来源:data.py

示例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
开发者ID:marvelliu,项目名称:flickr2weibo,代码行数:11,代码来源:auth.py

示例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
开发者ID:vincentwyshan,项目名称:VGA,代码行数:11,代码来源:sina.py

示例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)
开发者ID:kwdhd,项目名称:zhan2weibo,代码行数:11,代码来源:weibo.py

示例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)
开发者ID:xipingwang,项目名称:twittersync,代码行数:12,代码来源:twittersync.py

示例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)
开发者ID:laddcn,项目名称:PCRemote,代码行数:12,代码来源:PCRemote.py

示例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
	
开发者ID:chengjun,项目名称:Research,代码行数:11,代码来源:weibo_api.py

示例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)
开发者ID:yimiqisan,项目名称:xiha,代码行数:13,代码来源:tools.py

示例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
开发者ID:matthewmayer,项目名称:laowaibo,代码行数:13,代码来源:main.py

示例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 ''
开发者ID:bsspirit,项目名称:DotABook,代码行数:14,代码来源:getSina_job.py

示例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
开发者ID:HIT-Coder,项目名称:SmartWall,代码行数:55,代码来源:run.py

示例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()
开发者ID:renorzr,项目名称:twsync,代码行数:54,代码来源:sinaclient.py

示例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 ''
开发者ID:Zhanglingit,项目名称:iSeeu,代码行数:52,代码来源:sina_sdk.py


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