Dymantic / laravel-instagram-feed

150 stars 51 forks source link

Problem with getting access token #40

Closed OtiZ2 closed 3 years ago

OtiZ2 commented 3 years ago

I get this message right after click on allow.

Client error: POST https://api.instagram.com/oauth/access_token resulted in a 400 Bad Request response: {"error_type": "OAuthException", "code": 400, "error_message": "Error validating verification code. Please make sure you (truncated...)

image

image

michaeljoyner commented 3 years ago

Hi @OtiZ2 sorry to hear you are having issues. Can I ask which version you are using?

OtiZ2 commented 3 years ago

Hi, "laravel/framework": "^7.0", "dymantic/laravel-instagram-feed": "^2.6",

michaeljoyner commented 3 years ago

Okay, thanks. And have you added your Instagram account as a test user?

OtiZ2 commented 3 years ago

image

michaeljoyner commented 3 years ago

Alright, great. Next step is to check if there is anything in the logs which can give us more info. The package should log the error.

OtiZ2 commented 3 years ago

In the /storage/logs/laravel.log is just this

image

This call return the error message image

michaeljoyner commented 3 years ago

Yes, that makes sense. What domain are you starting the auth request from? Is this on your dev environment?

OtiZ2 commented 3 years ago

I try localhost, and production domain. Same result. https://lulu.upcyklovane.com/instagram/auth/callback

michaeljoyner commented 3 years ago

Okay. The problem seems to be that there is somehow a difference between the redirect_uri sent when starting the auth process, and when exchanging the code for a token. Can you possibly show me your config file?

OtiZ2 commented 3 years ago

Config file image

michaeljoyner commented 3 years ago

Ho @OtiZ2 have you managed to have any progress on this? I can't any issues with your config file. I have just tested with a fresh Laravel install and a fresh Instagram/FB app and it worked fine, so I'm not sure what to suggest. What do you have set as your APP_URL in your .env file?

OtiZ2 commented 3 years ago

This is from .env image

michaeljoyner commented 3 years ago

Hi @OtiZ2 Sorry for the late reply, I was away. Unfortunately I cannot think of what the problem is. The only idea I currently have is for you to manually edit the redirectUriForProfile method in the Instagram.php file in the package, and log out the value of the url before it is returned. That method gets called twice in the OAuth process, and the value it returns should be the same, but it seems that in your case it is not. Maybe by logging it and checking what value is returned we can find something useful.

https://github.com/Dymantic/laravel-instagram-feed/blob/88d5c69034a8690b0056cb91f8139cfadc552724/src/Instagram.php#L43-L49

OtiZ2 commented 3 years ago

Hi, this is log output: [2021-08-09 08:29:04] production.ERROR: redirectUriForProfile: {https://lulu.upcyklovane.com}/{instagram/auth/callback}

[2021-08-09 08:56:15] production.ERROR: redirectUriForProfile: {https://lulu.upcyklovane.com}/{instagram/auth/callback}
[2021-08-09 08:56:15] production.ERROR: https://lulu.upcyklovane.com/instagram/auth/callback
[2021-08-09 08:56:16] production.ERROR: Instagram auth error: unknown error message

image

image

michaeljoyner commented 3 years ago

Hmmm, that seems all correct. Can you please send a screenshot of the original error you are getting.

julianlaibach commented 3 years ago

Hey, thank you for your greate Package! Im facing the same Issue on my local development... Seems to have nothing to do with the Redirect URL if i change it than i get an Error response before authenticating. Did you found a Solution on this? On the Facebook Site im using the Instagram Basic Display App, is this the right one? Thank you!

michaeljoyner commented 3 years ago

HI @julianlaibach, sorry you experiencing issues. I'm not sure if @OtiZ2 ever found a solution for the above. Can you tell me a bit more about your setup and everything (what dev environment you are using, what version of this package and Laravel, etc) and I can try assist you. Have you also added yourself as a test Instagram user on the Facebook app you created? Yes, Instagram Basic Display is the correct one.

julianlaibach commented 3 years ago

Hi Michael, thank you for your Response! As a Dev environment i use a Docker Container. I also have a SSL Certificate on the Local URL. The Package Version is 2.6 The Laravel Version is 8.0 Both the URL in the config and the URL at Facebook are the same. Yes i also added the Test user and verified it in my Instagram Account. Its somehow strange because i dont know what to do else, i think i tried everything @OtiZ2 did you found a Solution for this Problem? Thank you!

michaeljoyner commented 3 years ago

Hi @julianlaibach can you share a screenshot of the error you are getting?

julianlaibach commented 3 years ago

Sorry for my late reply... Here is everything from the Log File:

[2021-09-13 18:54:00] local.INFO: redirect URL: https://barth-fs.test/instagram/auth/callback [2021-09-13 18:54:17] local.INFO: redirect URL: https://barth-fs.test/instagram/auth/callback [2021-09-13 18:54:17] local.ERROR: Instagram auth error: unknown error message

Im not sure what exactly causes this, i tried nearly everything, also on production... The only thing im not sure about is do i need to do the App Review on Facebook? Also if i added the Account to the Test Users Thank you!

michaeljoyner commented 3 years ago

HI @julianlaibach no worries. Do you see an error of any sort during the auth process? The error logging in this package is not so robust, and isn't providing enough info for the error. It would be helpful if I could see the actual error or response you get during the auth process.

I don't think facebook app needs to go through App Review, just make sure it is live, and you have set up the Instagram account as a Test Instagram User, and approved the request from Instagram.

julianlaibach commented 3 years ago

Hi Michael, so i think maybe im a bit closer...

[2021-09-14 06:53:06] local.ERROR: Exception: Dymantic\InstagramFeed\Exceptions\AccessTokenRequestException: Client error: POST https://api.instagram.com/oauth/access_token resulted in a 400 Bad Request response: {"error_type": "OAuthException", "code": 400, "error_message": "Error validating verification code. Please make sure you (truncated...) in /var/www/html/vendor/dymantic/laravel-instagram-feed/src/Profile.php:62

This is what i'm getting if i Log the Exception in AccessTokenController / handleRedirect If i google the Error i get the same hint as mentioned from you, the Redirect URI but i tested and im sure that those both match...

Do you have any thoughts on it? Best Julian

michaeljoyner commented 3 years ago

H @julianlaibach, sorry about the late reply. I am at a bit of a loss, I can't really find any new information about this, and I can see from your logs above that the redirect_uri is the same, so I can't see where the problem is. One idea, but it is a bit of a stretch, is that I give you the API key and secret for a FB/Instagram app that I know is working, and add your IG account as a test user, and see if the error is the same. At least this will be able to rule out whether it is an issue on the Facebook settings side, or something with the package.

michaeljoyner commented 3 years ago

I'm going to close this for now, if anyone has a similar issue please open a new issue.

OtiZ2 commented 3 years ago

hi everyone, sorry for late reply. No do not find any solution for this yet.

michaeljoyner commented 3 years ago

Hi @OtiZ2 I can only offer you the same thing as I offered @julianlaibach above, where you can try your setup using a FB app that is known to work

ley-288 commented 2 years ago

Had this problem using same versions. Personally had to install this package manually without composer and ran into multiple problems. Resolved this issue by manually adding Dymantic Package to Bootstrap cache Packages.php & Services.php.

omarherri commented 1 year ago

I did run into the same problem, so i removed the app from the connected applications in Instagram.

You can follow also this guide: https://smashballoon.com/doc/instagram-api-error-message-reference/