jsmrtn / craftagram

Grab Instagram content through the Instagram Basic Display API
Other
14 stars 8 forks source link

"Undefined index: query" #43

Closed gjhead closed 3 years ago

gjhead commented 3 years ago

Running Craftagram 1.44 along with:

PHP version: 7.4.16 OS version: Linux 4.19.0-11-amd64 Database driver & version: MySQL 5.5.5 Image driver & version: Imagick 3.4.4 (ImageMagick 7.0.10-57) Craft edition & version: Craft Pro 3.6.14 Yii version: 2.0.42.1 Twig version: v2.14.4 Guzzle version: 7.3.0

I am using Craftagram on 3 sites using Multisite in one Craft install. Previously working flawlessly. Added it to a fourth site today and keep getting an error on my "/actions/craftagram/default/auth" url. While troubleshooting, I found out that for all of my sites in my multisite install, I am getting the same error.

"Undefined index: query"

Any idea what could be causing this?

gjhead commented 3 years ago

I can share a Stacktrace log if needed.

jsmrtn commented 3 years ago

@gjhead Could you share the full URL you're receiving when you're redirected to actions/craftagram/default/auth please? This was reported a couple of days ago #42 which turned out to be an issue with the redirect URI.

gjhead commented 3 years ago

Sure:

https://premierprotein.co.uk/actions/craftagram/default/auth https://premierprotein.com/actions/craftagram/default/auth https://premierprotein.ca/actions/craftagram/default/auth

(Sorry these are live and not in dev mode - would a link to staging help? If so would rather send privately)

jsmrtn commented 3 years ago

Sure, you can get me on discord at jsm#5891.

Just to clarify your steps:

  1. Hit Authorise Craft
  2. Deal with all the Instagram authentication stuff their side
  3. Redirected back to your site on the auth action and seeing error?

You should be getting sent back to the auth page with a full range of bits as query params in the URL, are you just being sent back to the plain auth URL?

gjhead commented 3 years ago

Here you go: https://www.instagram.com/oauth/authorize?client_id=479148739995525&scope=user_profile,user_media&response_type=code&redirect_uri=https://www.premierprotein.com/actions/craftagram/default/auth&state=4

Now it is giving me this and a:

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

jsmrtn commented 3 years ago

@gjhead Sorry–not quite what I'm after, I need the full URL after you go through the oauth process. You will be redirected back to the auth controller endpoint, something like

https://scaramanga.test/actions/craftagram/default/auth?code=AQCnhfo3OGqYKMPLcaxpdVis8-EPZTXI1C1-oq1_OUfEMnh65VfFki8PqL-D22bqzxcYdJ5qqr84uEiXAoM1LDewKiwwiq7LKROW3zw7iLY9BWXd78QxXJIeruESpbOvG3dUEMA_1LBauTFYVQA0IlCdO7IXLf13T4z56qkPUcHf7kjW_MwFvyUUGx_N88zNe7hzaPx2YCQU4z9VQDfWDZOyuvWBMIt3LjaCuqNQTi8h7g&state=3#_

If you're seeing Undefined index: query then you're ending up on the auth controller endpoint without any information being appended by Instagram, which means that something has failed along the way with the authentication.

Your new message (invalid redirect_uri) means your app setup is incorrect, whatever you have set up in developers doesn't match https://www.premierprotein.com/actions/craftagram/default/auth

jsmrtn commented 3 years ago

@gjhead Did you delete a comment? If so–I'm not sure how you got that URL, as it doesn't have a state parameter, which is automatically appended.

Can you clarify you're following the steps from https://github.com/scaramangagency/craftagram/issues/43#issuecomment-840531271? We might need to jump on a screen share or something because I'm at a loss here.

gjhead commented 3 years ago

I did - but wanted to double check before posting. I'm planning on diving into this some more today to see what the deal is. I should be able to provide some clearer issues. One thing I can confirm, is that on two other sites I have that have been running Craftagram for a while now, will kick back an error when I hit the "Authorize Craft" button. Although they still seem to be pulling in the feed.

On Tue, May 18, 2021 at 4:36 AM Joshua Martin @.***> wrote:

@gjhead https://github.com/gjhead Did you delete a comment? If so–I'm not sure how you got that URL, as it doesn't have a state parameter, which is automatically appended.

Can you clarify you're following the steps from #43 (comment) https://github.com/scaramangagency/craftagram/issues/43#issuecomment-840531271? We might need to jump on a screen share or something because I'm at a loss here.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scaramangagency/craftagram/issues/43#issuecomment-842973580, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABO77DW6E6DPS2H5DJT7BTTOIRHNANCNFSM44ZDP6OQ .

gjhead commented 3 years ago

Hey @joshua-martin sorry for the delay on this. So I figured out one issue, which wasn't very clear in any documentation (including Facebook) and could be of use to anyone else with this use case.

When authenticating your Instagram test user, with the following link:

https://api.instagram.com/oauth/authorize ?client_id={app-id} &redirect_uri={redirect-uri} &scope=user_profile,user_media &response_type=code

This will only work if you are logged into Instagram with the specific user in your current browser session.

However, I am not still seeing an error on callback. Specifically getting an error that states:

Undefined index: state

i can send you a screencap of the error as well as the full URL, but would rather do that via email as it's on a live site.

jsmrtn commented 3 years ago

Sure–you can drop me a line at [redact]

gjhead commented 3 years ago

Oh man. Well, I finally got this to work. A bit of a pain, but I'll walk you through the steps.

1: When authenticating your Instagram test user, with the following link:

https://api.instagram.com/oauth/authorize ?client_id={app-id} &redirect_uri={redirect-uri} &scope=user_profile,user_media &response_type=code

This will only work if you are logged into Instagram with the specific user in your current browser session.

2: For your callback URL - always use your base admin url for the callback. Don't use the URL of the specific site in your multisite that you are trying to authenticate.

  1. Even then, I STILL get an error on return to my callback url, BUT, in that URL, you can manually grab your long access token: EX: https://domain.com/actions/craftagram/auth?code=YOURVERYLONGCODE

You can copy this code and enter it manually on your Craftagram settings page.

Then, hit "Authorize Craft" and everything finally works!

jsmrtn commented 3 years ago

Thanks @gjhead. Not sure whether this is a strange edge-case-cached-user-issue or whether there's a wider exploration that needs to be undertaken here (specifically for point 2, anyway). Glad to hear you've got it sorted–I'll go in and see if I can replicate with your instructions

gjhead commented 3 years ago

Thanks for being patient with me!

jsmrtn commented 3 years ago

@gjhead No worries, we've all been there!

This will only work if you are logged into Instagram with the specific user in your current browser session.

I have added a note to this effect in the README.

For your callback URL - always use your base admin url for the callback. Don't use the URL of the specific site in your multisite that you are trying to authenticate.

This is actually in the README as point 6.2, though I appreciate it is very much a throwaway line that's easily missed. I've updated the README to pull this out right at the top so that it isn't missed in future!

I cannot replicate for the life of me your point 3 issue still, I'm afraid. Being you have it sorted now, I can only assume it was a gremlin somewhere in the chain of issues that led to this point!