<s> from flask import Flask , redirect , url_for , session , request , jsonify <EOL> from flask_oauthlib . client import OAuth <EOL> app = Flask ( __name__ ) <EOL> app . debug = True <EOL> app . secret_key = '<STR_LIT>' <EOL> oauth = OAuth ( app ) <EOL> weibo = oauth . remote_app ( <EOL> '<STR_LIT>' , <EOL> consumer_key = '<STR_LIT>' , <EOL> consumer_secret = '<STR_LIT>' , <EOL> request_token_params = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> base_url = '<STR_LIT>' , <EOL> authorize_url = '<STR_LIT>' , <EOL> request_token_url = None , <EOL> access_token_method = '<STR_LIT:POST>' , <EOL> access_token_url = '<STR_LIT>' , <EOL> content_type = '<STR_LIT:application/json>' , <EOL> ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> if '<STR_LIT>' in session : <EOL> access_token = session [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> resp = weibo . get ( '<STR_LIT>' ) <EOL> return jsonify ( resp . data ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def login ( ) : <EOL> return weibo . authorize ( callback = url_for ( '<STR_LIT>' , <EOL> next = request . args . get ( '<STR_LIT>' ) or request . referrer or None , <EOL> _external = True ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def logout ( ) : <EOL> session . pop ( '<STR_LIT>' , None ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def authorized ( ) : <EOL> resp = weibo . authorized_response ( ) <EOL> if resp is None : <EOL> return '<STR_LIT>' % ( <EOL> request . args [ '<STR_LIT>' ] , <EOL> request . args [ '<STR_LIT>' ] <EOL> ) <EOL> session [ '<STR_LIT>' ] = ( resp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> @ weibo . tokengetter <EOL> def get_weibo_oauth_token ( ) : <EOL> return session . get ( '<STR_LIT>' ) <EOL> def change_weibo_header ( uri , headers , body ) : <EOL> """<STR_LIT>""" <EOL> auth = headers . get ( '<STR_LIT>' ) <EOL> if auth : <EOL> auth = auth . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> headers [ '<STR_LIT>' ] = auth <EOL> return uri , headers , body <EOL> weibo . pre_request = change_weibo_header <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
