Dymantic / laravel-instagram-feed

147 stars 51 forks source link

Media Expired (URL signature expired) & Refresh Throws http 400 error #54

Closed kinger251285 closed 2 years ago

kinger251285 commented 2 years ago

Hi

I have just logged into one of my projects and i am receiving this error:

Http request to https://graph.instagram.com/5069349379818774/media?fields=caption,id,media_type,media_url,thumbnail_url,permalink,children{media_type,media_url},timestamp&limit=20&access_token=MYACCESS TOKEN failed with a status of 400 and error message: unknown error

The error points to this part of my code:

$ThisFeed = $profile?->refreshFeed(21);

I remove the code above and then i receive no images, i open the image in a new tab and receive 'URL signature expired' which points to the Instagram CDN image expiring.

Ive added a refresh back in like below:

$feed = \Dymantic\InstagramFeed\InstagramFeed::for('some_account', 21)->refresh()->collect();

However i get the original error which points to this line of code.

michaeljoyner commented 2 years ago

Hi @kinger251285 it is possibly because you haven't refreshed your API token. You can try run "php artisan instagram-feed:refresh-tokens"

kinger251285 commented 2 years ago

Hi @kinger251285 it is possibly because you haven't refreshed your API token. You can try run "php artisan instagram-feed:refresh-tokens"

Thanks for coming back to me so quickly.

I tried that and got the below error:

Http request to https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=MYTOKEn failed with a status of 400 and error message: unknown error

Googling more it looks like Instagram may be having issues themselves

michaeljoyner commented 2 years ago

Okay, thanks. I'm not at home at the moment, but I'll try take a look first thing tomorrow.

michaeljoyner commented 2 years ago

Hi @kinger251285 are you still having the same issue? Everything seems fine from my end.

kinger251285 commented 2 years ago

Hi @kinger251285 are you still having the same issue? Everything seems fine from my end.

Sorry for the delayed reply, still having the same issue and get the same error when trying to refresh the token too.

michaeljoyner commented 2 years ago

Hi @kinger251285, sorry for the late reply. I think I know what the current error is coming from. You need to update the package, Instagram made a change a while back on how it handled the request url, which required a new version to be released. Please update via composer and the let me know if you still have issues. Thanks.

kinger251285 commented 2 years ago

Hi @michaeljoyner, I've just updated the package from v3.0.0 to v3.1.1 and im still getting the same issue

michaeljoyner commented 2 years ago

My apologies @kinger251285, I was mistaken there. I'm afraid I still don't know what is going wrong for you. Have you tried re-authorising the account to get a new token?

kinger251285 commented 2 years ago

@michaeljoyner Problem still persists and have noticed it is now also happening on another site ive created using this package.

On the Second Site i get the error when trying to access images - URL Signature Expired.

Things ive tried since:

In the Facebook Developers panel - Regenerated the Instagram Token for the test user, reset the Instagram App Secret and ensured all the checks are done to ensure the app is live rather than in developer mode.

I then retried - php artisan instagram-feed:refresh-tokens, php artisan config:clear, cleared all the site cache and rebuilt the node packages

This is still throwing the same errors as previous.

kinger251285 commented 2 years ago

@michaeljoyner So ive managed to figure a fix but obviously don't want to do this every time it breaks.

The token i regenerated manually I've replaced the old token in the DB manually. I've then run PHP artisan instagram-feed:refresh-tokens which ran fine. I've then added the refreshFeed back in and all is working fine.

Im guessing my token expired and that was causing the errors.

I know this is in the OAuth guide now but it may be worth clearly adding them to the main docs to ensure a cron is setup to run the refresh tokens command every 59 days.

It also may be worth adding some logic to check if the token is expired, if expired instead of returning the feed return - "Your Instagram Tokens Have Expired Please Refresh Your Token Manually".