Beispiel #1
0
class AppConfig(object):
    DEBUG = True
    SECRET_KEY = 'your-secret-key'
    DOUBAN_CLIENT_ID = 'your-api-key'
    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')
Beispiel #2
0
from flask import Flask, url_for, session, jsonify
from flask.ext.oauthlib.contrib.client import OAuth


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())