Oğuz Kurukaya
Oğuz Kurukaya

Reputation: 141

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

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.

Upvotes: 8

Views: 27850

Answers (7)

Mohammed Aflah
Mohammed Aflah

Reputation: 1

Please check that redirect uri you are passig through API must match exactly with the redirect uri mentioned in Meta developer settings.

Upvotes: 0

Aashutosh Kumar
Aashutosh Kumar

Reputation: 831

As per documentation

Construct the Authorization Window URL below, replacing {app-id} with your Instagram app’s ID (from the App Dashboard > Products > Instagram

Basic Display > Instagram App ID field) and {redirect-uri} with your website URL that you provided in Step 2 ("Valid OAuth Redirect URIs"). The URL must be exactly the same.

Syntax & Example as below

https://api.instagram.com/oauth/authorize?client_id=<instagram_app_id>&redirect_uri=<my-website>&scope=user_profile,user_media&response_type=code

https://api.instagram.com/oauth/authorize?client_id=00000123&redirect_uri=https://aashutosh-kumar.herokuapp.com/&scope=user_profile,user_media&response_type=code

Upvotes: 0

vadzim dvorak
vadzim dvorak

Reputation: 959

Go to https://developers.facebook.com/apps/APP_ID/instagram-basic-display/basic-display/ -> Client OAuth Settings and put there not just https://localhost:5000, but exact authentication endpoint used in your application (https://localhost:5000/auth or else)

Upvotes: 2

json
json

Reputation: 141

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)

Upvotes: 7

umbe1987
umbe1987

Reputation: 3578

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!

Upvotes: 1

Roy Martinez
Roy Martinez

Reputation: 358

I had the same problem and I solved it as following:
I first went here: (remember to change your instagram app id in the below URL) https://developers.facebook.com/apps/your_instagram_app_id/instagram-basic-display/basic-display/

Then I set my Client OAuth Settings, Deauthorize and Data Deletion Requests as "https://localhost:3000/".

That worked for me.

Upvotes: 5

RamonDB
RamonDB

Reputation: 71

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.

Upvotes: 7

Related Questions