def main(): FILE = os.curdir logging.basicConfig(filename=os.path.join(FILE, 'log.txt'), level=logging.INFO) config_init() print('APP_KEY:%s APP_SECRET:%s CALLBACK_URL:%s' % (APP_KEY, APP_SECRET, CALLBACK_URL)) client = APIClient(SinaWeiboMixin, app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) url = client.get_authorize_url() # redirect the user to 'url' print(url) # needGetCode = raw_input("Do you need to get code from callback in browser? Please input yes or no!") needGetCode = 'no' code = '' r = {} if needGetCode == 'yes': code = raw_input("Please input the returned code : " ) # redirect to url and get code r = client.request_access_token(code) print(r.access_token) # access token,e.g., abc123xyz456 print( r.expires ) # token expires time, UNIX timestamp, e.g., 1384826449.252 (10:01 am, 19 Nov 2013, UTC+8:00) # 测试版本access_token的时间期限为1天,过期后再重新获取 access_token = '2.00TD47_Gv7rSwB6b1fbd6797YonR5C' expires = 1622967755.0 client.set_access_token(access_token, expires) # After Initialize API Authorization... get_blog_and_process(client) print('get_blog_and_process is over...')
def get_newest_publicweibo(client): ''' get newest friend microblog ''' jsdict = {} try: jsdict = client.statuses.friends_timeline.get(page=1, count=180) except Exception as e: logging.error('>>>>>>>>>>get_newest_publicweibo ERROR : %s %s' % (datetime.now(), e)) print('>>>>GET ERROR') del client time.sleep(10) config_init() client = APIClient(SinaWeiboMixin, app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) url = client.get_authorize_url() # redirect the user to 'url' access_token = '2.00TD47_Gv7rSwBd7c70e9da30PlWbc' expires = 1614584749.0 client.set_access_token(access_token, expires) jsdict = get_newest_publicweibo(client) logging.error('>>>>>>>>>> %s' % jsdict) finally: return jsdict
def create_client(): client = APIC(WbM, app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) client.set_access_token(ACCESS_TOKEN, EXPIRES) return client
def create_client(): client = APIC(WbM, app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) client.set_access_token(ACCESS_TOKEN, EXPIRES) return client