老师代码如下,运行时报access_token错误,不知道哪里出错
import json
import requests
from flask import Flask, redirect, request
app = Flask(__name__)
def get_ticket():
url = 'https://api.weibo.com/oauth2/authorize?client_id=1548116460&response_type=code&redirect_uri=http://test.baidu.com'
# get请求
return url
def get_token(code):
url = 'https://api.weibo.com/oauth2/access_token?client_id=1548116460&client_secret=e7484b2aec003f14fd7a814f83366a5b&grant_type=authorization_code&redirect_uri=http://test.baidu.comI&code=' + code
resp = requests.post(url)
return resp.json()
def get_info(access_token, uid):
url = 'https://api.weibo.com/2/users/show.json'
resp = requests.get(url, {
'access_token': access_token,
'uid': uid
})
return resp.json()
@app.route('/')
def index():
code = request.args.get('code', None)
# 根据code获取token
token = get_token(code)
# 获取用户信息
user_info = get_info(token['access_token'], token['uid'])
return json.dumps(user_info)
@app.route('/weibo')
def weibo():
t = get_ticket()
return redirect(t)
if __name__ == '__main__':
app.run(debug=True, port=80)