jsmrtn / craftagram

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

Undefined property: stdClass::$access_token error when authorizing #58

Closed simonkuran closed 1 year ago

simonkuran commented 1 year ago

When Instagram redirects back to the site after I approve the authorization I get a "Undefined property: stdClass::$access_token" error. Do you know what could be causing that?

I'm running Craft v3.6.10 and Craftagram v1.4.4.

jsmrtn commented 1 year ago

Can you post the full stack trace if possible, thanks

On Tue, 22 Nov 2022 at 17:05, simonkuran @.***> wrote:

When Instagram redirects back to the site after I approve the authorization I get a "Undefined property: stdClass::$access_token" error. Do you know what could be causing that?

I'm running Craft v3.6.10 and Craftagram v1.4.4.

— Reply to this email directly, view it on GitHub https://github.com/scaramangagency/craftagram/issues/58, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM5Z3KW4NI3BPV2GJK5VKLWJT4LJANCNFSM6AAAAAASIBSDUA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

simonkuran commented 1 year ago

Here you go:

yii\base\ErrorException: Undefined property: stdClass::$access_token in /chroot/home/lswisced/ls.wisc.edu/vendor/scaramangagency/craftagram/src/services/CraftagramService.php:166 Stack trace:

0 /chroot/home/lswisced/ls.wisc.edu/vendor/craftcms/cms/src/web/ErrorHandler.php(77): yii\base\ErrorHandler->handleError(8, 'Undefined prope...', '/chroot/home/ls...', 166)

1 /chroot/home/lswisced/ls.wisc.edu/vendor/scaramangagency/craftagram/src/services/CraftagramService.php(166): craft\web\ErrorHandler->handleError(8, 'Undefined prope...', '/chroot/home/ls...', 166, Array)

2 /chroot/home/lswisced/ls.wisc.edu/vendor/scaramangagency/craftagram/src/services/CraftagramService.php(142): scaramangagency\craftagram\services\CraftagramService->getLongAccessToken('IGQVJYQ21tQkZAu...', '1', '$INSTAGRAMAPP...')

3 /chroot/home/lswisced/ls.wisc.edu/vendor/scaramangagency/craftagram/src/controllers/DefaultController.php(75): scaramangagency\craftagram\services\CraftagramService->getShortAccessToken('AQAoUcywk8t8voI...', '1')

4 [internal function]: scaramangagency\craftagram\controllers\DefaultController->actionAuth()

5 /chroot/home/lswisced/ls.wisc.edu/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

6 /chroot/home/lswisced/ls.wisc.edu/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)

7 /chroot/home/lswisced/ls.wisc.edu/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('auth', Array)

8 /chroot/home/lswisced/ls.wisc.edu/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('auth', Array)

9 /chroot/home/lswisced/ls.wisc.edu/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('craftagram/defa...', Array)

10 /chroot/home/lswisced/ls.wisc.edu/vendor/craftcms/cms/src/web/Application.php(577): craft\web\Application->runAction('craftagram/defa...', Array)

11 /chroot/home/lswisced/ls.wisc.edu/vendor/craftcms/cms/src/web/Application.php(253): craft\web\Application->_processActionRequest(Object(craft\web\Request))

12 /chroot/home/lswisced/ls.wisc.edu/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))

13 /chroot/home/lswisced/ls.wisc.edu/html/index.php(22): yii\base\Application->run()

14 {main}

simonkuran commented 1 year ago

@joshua-martin have you had a chance to look at this? We have a production site we'd like to fix. Thanks!

jsmrtn commented 1 year ago

@simonkuran Sorry, I hadn't had a chance to look into it until now. Presumably you're still seeing this issue?

Have you previously used this application for a different website? The only way I can replicate this is by trying to use an application that has already been authenticated on one domain on another domain, and even then it doesn't happen all of the time. It might be something to do with the authorisation code already being used (which doesn't appear to be that wide an issue, which would make sense given the auth codes only live for an hour - i.e. https://github.com/espresso-dev/instagram-basic-display-php/issues/14).

Is this a fresh application you have just created? The only thing I can think of that would really help is to go into /vendor/scaramangagency/craftagram/services/CraftagramService and dd(json_decode($res)) on after curl_close on line 138 and see what comes back.

simonkuran commented 1 year ago

@joshua-martin All good! The debugging on line 138 put me on the right track. Turns out there was a "API access deactivated. To reactivate, go to the app dashboard." error that wasn't coming through. I just needed to fix a couple items with my app in the Facebook developer portal.

By changing line 140 from $shortAccessToken = json_decode($res)->access_token; to $shortAccessToken = json_decode($res)->{'access_token'};

and line 167 from $token = json_decode($res)->access_token; to $token = json_decode($res)->{'access_token'};

then I was able to get the error to come through with dd(json_decode($res));

So the error was definitely on my end, but it would be great if the plugin could forward this useful error on to me by default. None of my edits were necessary once I resolved the Facebook issue.

If you're testing this, I believe disabling the app in Facebook should trigger this issue.

Thanks for your help!