本文整理汇总了Python中database.User.access_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.access_token方法的具体用法?Python User.access_token怎么用?Python User.access_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.access_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authorized
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import access_token [as 别名]
def authorized():
global facebook_graph
# check to make sure the user authorized the request
if not 'code' in request.args:
flash('You did not authorize the request')
return redirect(url_for('index'))
code = request.args['code']
access_token_url = 'https://graph.facebook.com/oauth/access_token'
access_token_url_params = {'client_id': app.config['FB_CLIENT_ID'],
'redirect_uri': url_for('login.authorized', _external=True),
'client_secret': app.config['FB_CLIENT_SECRET'],
'code': code
}
access_token_text = requests.get(access_token_url, params=access_token_url_params).text
access_token = re.split('=|&', access_token_text)[1]
facebook_graph = facebook.GraphAPI(access_token)
me = facebook_graph.get_object("me")
fb_id = me['id']
session['fb_id'] = fb_id
session['name'] = me['name']
session['logged_in'] = True
user = User.query.filter_by(fb_id=fb_id).first()
if user is None:
user = User(fb_id, access_token)
db.session.add(user)
db.session.commit()
else:
user.access_token = access_token
db.session.merge(user)
db.session.commit()
return redirect(url_for('index'))