Instagram API调用中重定向URI的格式 [英] Formatting of Redirect URI in Instagram API Calls

查看:254
本文介绍了Instagram API调用中重定向URI的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Webpy编写python脚本,以获取Instagram用户的身份验证令牌,并且不断提出反对重定向URI与原始重定向URI不匹配".它有点像这样:

I'm writing a python script using webpy to grab an authentication token for an Instagram user, and I keep bumping up against "Redirect URI doesn't match original redirect URI". It goes a little something like this:

第1步
用户首先访问http://localhost:8081/join以单击将其发送到Instagram登录页面的按钮,然后要求他们允许该应用访问其供稿:

Step 1
The user first visits http://localhost:8081/join to click a button which sends them off to the Instagram login page, where they're asked to allow the app to access their feed:

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步
该脚本将返回的代码附加到URL上,重定向到http://localhost:8081/request-token.目前,这部分工作正常.然后,我获取代码并尝试获取访问令牌.我已经使用python-instagram库和pycurl尝试了这一部分,如下所示:

Step 2
The script redirects to http://localhost:8081/request-token with the returned code appended to the URL. This part works just fine at the moment. I then grab the code and try to get an access token. I've tried this part with the python-instagram library and pycurl, as seen below:

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"}

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

My current client settings look like this:

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

But no matter what redirect URI I seem to use at this point, I get the same message. Any help is appreciated!

推荐答案

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

The redirect URI that you use in the second call to exchange the code for the access token must match the redirect URI used in the first call to obtain the code. From the documentation:

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

redirect_uri: the redirect_uri you used in the authorization request. Note: this has to be the same value as in the authorization request.

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

这篇关于Instagram API调用中重定向URI的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆