我正在尝试创建一个链接Basecamp API的应用程序。 我正在使用flask-dance提供的自定义蓝图。 https://flask-dance.readthedocs.io/en/latest/providers.html#module-flask_dance.contrib.facebook
我正在尝试将我的应用重定向到basecamp登录页面,但它指出此错误: AttributeError:“ OAuth2ConsumerBlueprint”对象没有属性“ get”
如何解决此错误?
from flask import Flask, url_for, request, jsonify, session, redirect
from flask_dance.consumer import OAuth2ConsumerBlueprint
from flask_oauthlib.client import OAuth
app = Flask(__name__)
oauth = OAuth()
basecamp = OAuth2ConsumerBlueprint(
"basecamp", __name__,
client_id="",
client_secret="",
base_url="",
token_url="https://launchpad.37signals.com/authorization/token",
authorization_url='https://launchpad.37signals.com/authorization/new?type=web_server',
)
app.register_blueprint(basecamp, url_prefix='/basecamp_login')
@app.route('/basecamp')
def basecamp_login():
if not basecamp.authorized:
return redirect(url_for('basecamp.base_url'))
account_info = basecamp.get('/email_address')
if account_info.ok:
account_info_json = account_info.json()
return '<h1>Your basecamp email address is{}'.format()
if __name__ == '__main__':
app.run(debug=True)
答案 0 :(得分:0)
如the documentation for custom Flask-Dance providers中所述,您需要引用蓝图上的session
属性以发出HTTP请求。在您的情况下,basecamp.get('/email_address')
是错误的,因为basecamp
是OAuth2ConsumerBlueprint
对象。您应该改为致电basecamp.session.get('/email_address')
。