Future of Instagram Plugin

Ah, nope. It still works. Fault was on my side (multi-language mistake). :upside_down_face:

Glad it works for you. I went the Facebook app route. Seems you can add some IG accounts there as ‘test users’ and just keep refreshing the long-lived token without needing app approval.

@phm, I’m finding that I need to take the same route as you (Facebook app) on this. I’m wondering if you can share you’re snippet that pulls the data from Instagram. When the client requested they wanted their latest Instagram posts I thought I’d be able to figure this out and execute the feature in a couple hours, but I feel like Alice in Wonderland. I suppose after the API updates lots of the working example no longer work and we have to jump through more hoops to make this function. Any insight would be appreciated.

@thewebprojects You can add a test user (should be a real instagram account) for your app in the facebook developer console and generate an access token for that user which remains valid for 60 days. Can’t point you to the documentation for this as it’s a year ago and their documentation site has changed a lot in the meantime but I’m sure you’ll find it on developers.facebook.com.

I then set up my own api endpoint where I read the access token from a .env file (left that part out of the example below) and then just call the IG api:

$url = "https://graph.instagram.com/me/media?fields=id,media_type,media_url,permalink,timestamp,caption&access_token=$access_token";

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 01 Jan 1996 00:00:00 GMT');
header('Content-type: application/json');

// get posts
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

if(!$result) {
  http_response_code(503);
  echo json_encode(['error' => 'Instagram server not responding']);
} else {
  $data = json_decode($result, true);
  if(isset($data["data"])) {
    $posts = $data["data"];  
    echo json_encode($posts);
  } else {
    http_response_code(503);
    echo json_encode(['error' => 'No data']);
  }
}

Secondly: the access token only lives for 60 days, so you need to refresh it before it expires. Same thing but with this url:

$url = "https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=$access_token";

I do this with a daily cron job but it could be monthly of course. So far it works.

Caveat: I’m not the most experienced api builder, the error checking/throwing bit is probably sketchy.

Very kind of you to share your work. Thanks @phm.

What products do you have on the Facebook app you created? I suppose we need the Instagram Graph API?

@thewebprojects I’m using Instagram Basic Display (had to look it up).

Hmm. This is part of my confusion. I see no Instagram Basic Display product. I wonder if it has something to do with my app type being ‘Business’. Is your app type business? Now I fee like I’m pullin’ you into my rabbit hole.

According to the Instagram Basic Display documentation, business apps are not supported. You would have to use the Instagram Graph API or create a new non-business app.

Thanks for the info @texnixe