Instagram oauth api gives { “code”: 400, “error_type”: “OAuthException”, “error_message”: “No matching code found.” }

房东的猫 提交于 2019-11-30 12:45:50

问题


I am working on an application that integrates with Instagram API to access the user information. I successfully fetch the Access Token using the authorize url but unable to fetch the userId using access_token url:

i am tried both the endpoints:

https://api.instagram.com/oauth/access_token?client_id=48275564e2c445f6b8e1356djfha3e0c&client_secret=ab2062da9f314e3489dke7ae9cbe6e5d&redirect_uri=http://localhost&grant_type=authorization_code

https://api.instagram.com/oauth/access_token

with the post body as:

client_id=48275564e2c445f6b8e1356djfha3e0c&client_secret=ab2062da9f314e3489dke7ae9cbe6e5d&redirect_uri=http://localhost&grant_type=authorization_code&code=1351860224.4827556.5dc92c4d15ea4a4ea1b0d33eaf0eef19

(The data in the request is modified), But i am getting the follwing

{
    "code": 400,
    "error_type": "OAuthException",
    "error_message": "No matching code found."
}

I have seen tons of queries and questions but could not find any solution to the problem.

The couple of questions i have is:

1) is the field code in the URL is same as access_token, if not how could i get the code field's value.

2) is there any other mechanism(API) to fetch the user details given the username is not known.

Please help me as i am completely stuck and running out my deadlines.


回答1:


For me unchecking Disable implicit OAuth in instagram developer -> manage clients fixed the issue




回答2:


I found that using either form-data or application/x-www-form-urlencoded works fine. The most important is the code you get from redirect uri is only used by one request. It means you could request the access token once for the code. If the you request more than one time with same code, you'll get the error like this:

{
    code: 400,
    error_type: "OAuthException",
    error_message: "Matching code was not found or was already used."
}

Wish you all the best ;)




回答3:


Try to urlEncode the redirect_uri param to

http%3A%2F%2Flocalhost

And your code param contains the "." character which might be a error.

code=1351860224.4827556.5dc92c4d15ea4a4ea1b0d33eaf0eef19

might caused the problem

"error_message": "No matching code found."

"5dc92c4d15ea4a4ea1b0d33eaf0eef19" seems to be the correct code




回答4:


I got same error. It seems that instagram's spam system disable user's access to any non-official application. Just change user's password. In my case it was help. Also try create another application.

UPD

From my answer to another question

It looks like users get more than one code, and you see first code, but need second. Try relogin users, if you gets error. User will not see instagram page with confirm button, just redirections.

Possible algorithm of error:

1. User click auth link.
2. Get first code.
3. User click auth link (twice, redirection problem, public auth system, etc.)
4. Get another code (even on the same client_id, redirect_uri).
5. You get first code.
6. But first code already doesn't exists.



回答5:


The problem is here that need redirect url set as http://localhost/signin-instagram

signin-instagram part is very important So go to Instagram.com/developer ->Manage Client-> Security -> Valid redirect URIs set with that end http:/../signin-instagram




回答6:


Off late instagram python snippet fails due to missing content-type HTTP header

response, content = http_object.request(url, method="POST", body=data,headers = {"Content-type": "application/x-www-form-urlencoded"})

adding application/x-www-form-urlencoded worked for me




回答7:


I will mention what worked for me.

Step 1. Generate a new client secret from you panel.

Step 2. Follow the step 1 mentioned here to obtain the code again.

Step 3. Send the request again with the changed parameters.

Make sure you are logged in the browser when you send the request. You will get the required response.



来源:https://stackoverflow.com/questions/23886843/instagram-oauth-api-gives-code-400-error-type-oauthexception-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!