我正在使用Instagram的OAuth身份验证服务(based on this description)的Flask网站上工作。我能够访问Instagram并获得身份验证所需的代码,但在最后一步,我收到一条错误消息,指出我没有" client_id"我想我已经提供了。
from flask import Flask, request, redirect
import requests
import json
client_id = ""
client_secret = ""
redirect_uri = ""
authorization_url = "https://api.instagram.com/oauth/authorize"
app = Flask(__name__)
app.debug = True
app.secret_key = 'development'
@app.route('/')
def index():
return redirect(authorization_url + "/?client_id=" + client_id + "&redirect_uri=" + redirect_uri + "&scope=public_content&response_type=code")
@app.route('/callback')
def callback():
code = request.args.get('code')
payload = {"client_id": client_id,
"client_secret": client_secret,
"grant_type": "authorization_code",
"redirect_uri": redirect_uri,
"code": code}
r = requests.post('https://api.instagram.com/oauth/access_token', data=json.dumps(payload))
return r.text
返回错误:
{"error_type": "OAuthException", "code": 400, "error_message": "You must provide a client_id"}
我发现这很奇怪,因为我在有效负载中提供了client_id。 可能是什么问题?
答案 0 :(得分:0)
看来,有效载荷不必是json,而是简单的字典。 使用以下表格:
r = requests.post('https://api.instagram.com/oauth/access_token', data=payload)