DOUBAN_CLIENT_SECRET = 'your-api-secret' DOUBAN_SCOPE = [ 'douban_basic_common', 'shuo_basic_r', ] app = Flask(__name__) app.config.from_object(AppConfig) app.config.from_pyfile('dev.cfg', silent=True) oauth = OAuth(app) # see also https://github.com/requests/requests-oauthlib/pull/138 douban = oauth.remote_app( name='douban', version='2', endpoint_url='https://api.douban.com/', access_token_url='https://www.douban.com/service/auth2/token', refresh_token_url='https://www.douban.com/service/auth2/token', authorization_url='https://www.douban.com/service/auth2/auth', compliance_fixes='.douban:douban_compliance_fix') @app.route('/') def home(): if obtain_douban_token(): response = douban.get('v2/user/~me') return jsonify(response=response.json()) return '<a href="%s">Login</a>' % url_for('oauth_douban') @app.route('/auth/douban') def oauth_douban():
class DefaultConfig(object): DEBUG = True SECRET_KEY = "your-secret-key" TWITTER_CONSUMER_KEY = "your-api-key" TWITTER_CONSUMER_SECRET = "your-api-secret" app = Flask(__name__) app.config.from_object(DefaultConfig) app.config.from_pyfile("dev.cfg", silent=True) oauth = OAuth(app) twitter = oauth.remote_app( name="twitter", version="1", endpoint_url="https://api.twitter.com/1.1/", request_token_url="https://api.twitter.com/oauth/request_token", access_token_url="https://api.twitter.com/oauth/access_token", authorization_url="https://api.twitter.com/oauth/authorize", ) @app.route("/") def home(): if oauth_twitter_token(): response = twitter.get("statuses/home_timeline.json") return jsonify(response=response.json()) return '<a href="%s">Login</a>' % url_for("oauth_twitter") @app.route("/auth/twitter") def oauth_twitter():