{"error_type": "OAuthException", "code": 400, "error_message": "Invalid redirect_uri"}

Viewed 18237

Firstly, this is my Instagram URL after the login:

https://www.instagram.com/oauth/authorize?client_id=$MYCLİENTİD&redirect_uri=https://localhost:4000/İnstagram/Insta.php/&response_type=code&scope=user_profile,user_media

And this is the error that page shows me:

{"error_type": "OAuthException", "code": 400, "error_message": "Invalid redirect_uri"}

When I try to get user token from Instagram, I get that error.
I've tried to change the redirect_uri=(Valid OAuth Redirect URIs), but the error is the same as before.

5 Answers

I could not find this documented anywhere, but through trial and error, I found that the redirect_uri had to:

  1. Use https
  2. Be publicly accessible (e.g. localhost and specifying a port number won't work)
  3. Not include parameters (I found they were getting stripped out, which would cause a redirect_uri mismatch when I later requested an access token)

Actually, for me, it was because my URI was not exactly the same as requested by the app. I forgot to add "/" at the end.

Actually, it does work with localhost, but it is very tedious.

  • First, you need to have https enabled (which from what I can see from your request you seem to have).

  • [I don't know if this is mandatory] you need to create a test app* from your main app (https://developers.facebook.com/docs/development/build-and-test/test-apps/)

  • Set the redirect OAuth URI to something like https://localhost:4000/auth/ and update also all other URIs in .../instagram-basic-display/basic-display/ settings.

  • Finally, don't forget to use the client-id(or app-id) of the test app in your request, which is different than your parent app

I wish you good luck ;)

*IMPORTANT: app-id and app-secret are different in test app!

Related