Instagram 中重定向 URI 的格式 API 调用

Formatting of Redirect URI in Instagram API Calls

我正在编写一个 python 脚本,使用 webpy 为 Instagram 用户获取身份验证令牌,但我一直遇到 "Redirect URI doesn't match original redirect URI"。它有点像这样:

步骤 1
用户首先访问 http://localhost:8081/join 以单击一个按钮,该按钮将他们发送到 Instagram 登录页面,在那里他们被要求允许该应用访问他们的提要:

class GetCode:

    def POST(self):

        data = web.input()
        username = data.username

        #Get Code...
        sendData = {"client_id": CONFIG['client_id'],"redirect_uri": "http://localhost:8081/request-token","response_type": "code"}
        codeRequest = requests.get('https://api.instagram.com/oauth/authorize/', params=sendData)

        web.seeother(codeRequest.url)

步骤 2
脚本重定向到 http://localhost:8081/request-token,返回的代码附加到 URL。这部分目前工作得很好。然后我获取代码并尝试获取访问令牌。我已经使用 python-instagram 库和 pycurl 尝试了这一部分,如下所示:

class RequestToken:

    def GET(self):
        received = web.input()
        code = received.code

        buffer = StringIO()

        data ={
            "client_id": CONFIG['client_id'],
            "client_secret": CONFIG['client_secret'],
            "grant_type":"authorization_code",
            "redirect_uri":"http://localhost:8081/success/",
            "code":code 
        }

        postData = urlencode(data)

        c = pycurl.Curl()
        c.setopt(c.HTTPHEADER, ["Content-type: application/x-www-form-urlencoded"])
        c.setopt(c.URL, 'https://api.instagram.com/oauth/access_token')
        c.setopt(c.POSTFIELDS, postData)
        c.setopt(c.WRITEDATA, buffer)
        c.setopt(c.VERBOSE, True)
        c.perform()

此时我收到 {"code": 400, "error_type": "OAuthException", "error_message": "Redirect URI doesn't match original redirect URI"}

我当前的客户端设置如下所示:

但无论此时我似乎使用什么重定向 URI,我都会收到相同的消息。感谢您的帮助!

您在第二次调用中用于交换访问令牌代码的重定向 URI 必须与第一次调用中用于获取代码的重定向 URI 匹配。来自文档:

redirect_uri:您在授权请求中使用的redirect_uri。注意:这必须与授权请求中的值相同。

https://instagram.com/developer/authentication/