def sendWangYiWeibo(self,text,imgno=None): userAccessToken=UserAccessToken.all().fetch(1) if userAccessToken and userAccessToken[0].wyisright: useracc=userAccessToken[0] else: return True t = TBlog(webSetting.wyconsumer_key, webSetting.wyconsumer_secret) t._request_handler.access_token = OAuthToken(useracc.wyToken,useracc.wySecret) try: imgdata='' # if imgno: # image = urlfetch.fetch(url=setting[0].dbphotoWebSite+'/s/'+imgno,deadline=10) # # if image.status_code == 200: # logging.info(setting[0].dbphotoWebSite+'/s/'+imgno) # bf=db.Blob(image.content) if imgno: imgulr=json.read(t.statuses_upload(imgno)) upload_image_url=imgulr['upload_image_url'] text=upload_image_url+' '+text result=t.statuses_update({'status':text.encode('utf-8')}) except Exception,e: logging.info('wy:'+str(e)) # logging.info('wy'+str(result)) # if str(result).find('40025')==-1: self.error(500) return False
def get(self): username=self.request.get('username') website=self.request.get('website') if not username: return # 获取oauth认证url if 'sina'==website: login_backurl =webSetting.WEIBOURL+'/login_check?username='******'&data='+str(datetime.now())+'&website=sina' auth_client = weibo.APIClient(webSetting.xlconsumer_key, webSetting.xlconsumer_secret, login_backurl) auth_url = auth_client.get_authorize_url() # 保存request_token,用户登录后需要使用它来获取access_token # memcache.Client().set(username+"_request_token1",auth_client.request_token,36000) # 跳转到登录页面 return self.redirect(auth_url) elif 'wy'==website: login_backurl =webSetting.WEIBOURL+'/login_check?username='******'&data='+str(datetime.now())+'&website=wy' t = TBlog(webSetting.wyconsumer_key, webSetting.wyconsumer_secret) t.get_request_token() url=t.get_auth_url(login_backurl) # 保存request_token,用户登录后需要使用它来获取access_token memcache.Client().set(username+"_request_token3",t,36000) return self.redirect(url) elif 'teng'==website: login_backurl=webSetting.WEIBOURL+'/login_check?username='******'&data='+str(datetime.now())+'&website=teng' auth=qqOAuthHandler(webSetting.qqconsumer_key,webSetting.qqconsumer_secret,callback=login_backurl) url=auth.get_authorization_url() # 保存request_token,用户登录后需要使用它来获取access_token memcache.Client().set(username+"_request_token4",auth,36000) return self.redirect(url)
def get(self): # 保存最初的登录url,以便认证成功后跳转回来 # back_to_url = _get_referer_url(request) # request.session['login_back_to_url'] = back_to_url website=self.request.get('website') # userAccessToken=UserAccessToken() # userAccessToken.sinaExpires='1522066881' # userAccessToken.sinaSecret='2.00HGNhqCdb1iQBb8eed27af80MRd2r' # userAccessToken.put() # logging.info(str(UserAccessToken().all().count())) # 获取oauth认证url # setting=Setting().all().fetch(1) # if setting: # setting=setting[0] # else: # return if 'sina'==website: login_backurl =webSetting.WEIBOURL+'/Admin/login_check?website=sina' auth_client = weibo.APIClient(webSetting.xlconsumer_key, webSetting.xlconsumer_secret, login_backurl) auth_url = auth_client.get_authorize_url() # 保存request_token,用户登录后需要使用它来获取access_token # user_request_token=memcache.Client().get(website+"_request_token1") # if not user_request_token: # user_request_token= auth_client.request_token # memcache.Client().set(website+"_request_token1",user_request_token,36000) # 跳转到登录页面 return self.redirect(auth_url) elif 'wy'==website: login_backurl =self.request.host_url+'/Admin/login_check?website=wy' t = TBlog(webSetting.wyconsumer_key, webSetting.wyconsumer_secret) t.get_request_token() url=t.get_auth_url(login_backurl) # 保存request_token,用户登录后需要使用它来获取access_token user_request_token=memcache.Client().get(website+"_request_token3") if not user_request_token: user_request_token= t memcache.Client().set(website+"_request_token3",user_request_token,36000) return self.redirect(url) elif 'teng'==website: login_backurl=self.request.host_url+'/Admin/login_check?website=teng' auth=qqOAuthHandler(webSetting.qqconsumer_key,webSetting.qqconsumer_secret,callback=login_backurl) url=auth.get_authorization_url() # 保存request_token,用户登录后需要使用它来获取access_token memcache.Client().set(website+"_request_token4",auth,36000) return self.redirect(url)
def get_authorzie_url(): t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) return t.get_auth_url() #copy the url to your browser and get PIN number
def get_request_token(): t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) return t.get_request_token()
def get_access_token(): t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) print t.get_auth_url() #copy the url to your browser and get PIN number verifier = raw_input('PIN: ').strip() #input PIN number return t.get_access_token(verifier)
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil token_util = TokenUtil() token_str = token_util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(token_str) print t.users_show({"name": '王有华'}) #tweet
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil util = TokenUtil() str = util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(str) print t.statuses_retweets({'id':'1112152297221206741', 'since_id':'-2551774633877939158'})
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil util = TokenUtil() str = util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(str) print t.statuses_retweets({ 'id': '1112152297221206741', 'since_id': '-2551774633877939158' })
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil import json content = "Hello From Python SDK" token_util = TokenUtil() token_str = token_util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(token_str) pic_url = json.read(t.statuses_upload("pic.jpg")) #upload picture content += pic_url["upload_image_url"] print t.statuses_update({"status": content}) #tweet
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil import json content = "Hello From Python SDK" token_util = TokenUtil() token_str = token_util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(token_str) pic_url = json.read(t.statuses_upload("pic.jpg")) #upload picture content +=pic_url["upload_image_url"] print t.statuses_update({"status":content}) #tweet
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' import json from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil util = TokenUtil() str = util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(str) friends = t.statuses_friends() result = json.read(friends) #get friends for friend in result["users"]: #Ĭ默认只返回30个关注列表 print friend["name"].decode("utf-8")
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil util = TokenUtil() str = util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(str) print t.statuses_home_timeline({'count':1,'trim_user':'******'}) #hometimeline
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil token_util = TokenUtil() token_str = token_util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(token_str) print t.users_show({"name":'王有华'}) #tweet
# -*- coding: utf-8 -*- ''' Created on Jul 29, 2011 @author: wangyouhua ''' from t4py.tblog.tblog import TBlog from t4py.tblog.constants import CONSUMER_KEY from t4py.tblog.constants import CONSUMER_SECRET from t4py.http.oauth import OAuthToken from t4py.utils.token_util import TokenUtil util = TokenUtil() str = util.get_token_str('user_test') t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(str) print t.statuses_home_timeline({ 'count': 1, 'trim_user': '******' }) #hometimeline
#! /usr/bin/env python #coding=utf-8 from config import * from utils import store_category, weibo_logger, weibo_date_str_to_datetime import json from t4py.tblog.tblog import TBlog from t4py.http.oauth import OAuthToken CONSUMER_KEY = 'mz2K4oGDKyWE3CFF' CONSUMER_SECRET = 'n6z7CHKXKv7OOSp4nG0dKjgNT5AHRTz5' token_str = 'oauth_token_secret=f4c70e9c470c67608e44041292d58b48&oauth_token=00dd97236502b7eb6d0e49ad16ad0dce' t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) t._request_handler.access_token = OAuthToken.from_string(token_str) NETEASE_WEIBO_INFO_SOURCE_ID = 8 def get_token(): t = TBlog(CONSUMER_KEY, CONSUMER_SECRET) print t.get_auth_url() #copy the url to your browser and get PIN number verifier = raw_input('PIN: ').strip() #input PIN number return t.get_access_token(verifier) def search_for_new_statuses(): previous_real_count = session.query(Status).count()