Jump to content

InstagramBasicDisplayApi


nbcommunication
 Share

Recommended Posts

Hey @nbcommunication, hey all...

since a few day's (don't know exactly when it startet) I've a problem getting the feed. I'm using this plugin on different sites with various accounts - so far had no problems with it. On 3 of these websites the feed doesn't load any more - on the other websites I suspect that the cache is not expired, yet. There are no items in the $instagram->getMedia() array any more - no errors are shown. When I review the modules settings this so what I got:

There is currently 1 cached request.

2080934359_2023-02-0308_18_16-Modul_InstagramBasicDisplayAPIvieregg-design.deMozillaFirefox.thumb.png.0b8294adf60aa57a14ee06384d1f6eb8.png

Clearing the cache doesn't help.

Anyone else facing this problem, any ideas how I could debug further?

Cheers and many greet!

Link to comment
Share on other sites

Indeed - didn't thought about this place to look for errors 🤦‍♂️

vor 8 Minuten
2023-02-03 09:29:01 	guest 	/ 	Could not process user media: {"error":{"message":"Error validating access token: The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons.","type":"OAuthException","code":190,"fbtrace_id":"A8JC4GfQtIPWPBs_P8YONKd"}}

vor 8 Minuten
2023-02-03 09:29:01 	guest 	/ 	Could not refresh long-lived access token

I expected the access token to be renewed automatically - the passwords of the corresponding pages were not changed.

Link to comment
Share on other sites

Hi @DV-JF,

Ah yes, this is a total pain when this happens. We've had this happen on sites where we don't have much contact with the client, as since we need them to re-authorise, the feed is just lying empty.

Anyway, going through the authorisation process again should fix this.

Cheers,

Chris

Link to comment
Share on other sites

27 minutes ago, nbcommunication said:

Ah yes, this is a total pain when this happens.

Can you tell me why it happens? Would it be possible to send an email to the admin, if the authentication process fails - any ideas?

Link to comment
Share on other sites

Hi @DV-JF,

It happens because Instagram/Facebook invalidates the (authorised) access token if the user changes their password. I guess from the error message (Facebook has changed the session for security reasons) other security issues can lead to it happening too.

It isn't in the scope of the module to notify admins, but it should be pretty easy to implement. Try something like:

<?php

$instagram = $modules->get('InstagramBasicDisplayApi');

$items = $instagram->getMedia();

if(!($items instanceof WireArray) || !$items->count) {
	$cache->getFor($instagram, 'errorNotifyAdmin', 'daily', function() use ($config, $instagram, $log, $mail) {
		return $mail->new()
			->to($config->adminEmail)
			->subject("$instagram error")
			->bodyHTML('<p>' . 
				implode('<br>', $log->getLines(
					$instagram->className(['lowercase' => true]),
					['limit' => 10]
				)) . 
			'</p>')
			->send();
	});
}

This would send the admin an email every day if no media is being returned, with the email being the last 10 log messages.

Cheers,

Chris

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...