jsmrtn / craftagram

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

Undefined property: stdClass::$access_token Cannot obtain access token when authorising Craft #68

Closed jamesmacwhite closed 8 months ago

jamesmacwhite commented 8 months ago

I have previously been able to authorise the connection a few months ago, but now cannot seem to authorise a token for use with the Instagram API. We had a refresh cron job running, but it appears the token had expired.

Debugging locally, there appears to be an OAuth error:

Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request.

One of the redirect URIs saved in the Client OAuth settings is: https://nottingham-college.ddev.site/actions/craftagram/default/auth

Instagram authorize URL (before clicking allow):

https://www.instagram.com/oauth/authorize/third_party?client_id=[secret]&scope=user_profile%2Cuser_media&response_type=code&redirect_uri=https%3A%2F%2Fnottingham-college.ddev.site%2Factions%2Fcraftagram%2Fdefault%2Fauth&state=1&logger_id=[logger_id]

The URL in the browser after this, when the error occurs.

https://nottingham-college.ddev.site/actions/craftagram/default/auth?code=[code]&state=1#_

I did notice the inclusion of #_ at the end of the URL, and tried to add an OAuth redirect URL with this after the auth path but that didn't solve it.

There was a recent Facebook/Instagram outage recently, I don't know if anything has changed or cause problems?

As far as I know the application setup should be correct based on the instructions and double checking the redirect URIs set do match.


Craft CMS: 3.9.10 Pro Craftagram: 1.4.6

jamesmacwhite commented 8 months ago

For info. If I interrupt the auth flow and get the code value before getShortAccessToken() runs so it doesn't get used and did a manual HTTP POST request outlined on: https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-access-tokens-and-permissions/#step-2--exchange-the-code-for-a-token. It appears to work fine.

{
    "access_token": "[redacted]",
    "user_id": "[redacted]"
}

I was able to paste the access_token provided in the response into Craft and this works.

jamesmacwhite commented 8 months ago

Right so the environment variable was wrong for the Instagram client secret! Doh. However, I had to create a new Facebook App, as the one that was used previously had the Facebook Login product added to it accidentally and you cannot remove products (right....) which may have cause issues with the app setup and broke it originally. Creating a new app was the solution, but only when you provide the correct details!

The OAuth error is somewhat not related to the actual problem, but in this case the client_secret was wrong!