0

I need to add only my personal Instagram posts to my personal website so I can use them as portfolio.

I don't want to do authenication every request is made and I don't want to use legecy api.

There is some answers here and there, some of them are outdated and some are incomplete (doesn't answer this question). I am looking an answer which summarize this and which I can go back to when I need.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98

2 Answers2

1

Assuming you already created a Instagram app, got a 1 hour token.


First you do something like this:

  GET https://graph.instagram.com/access_token
  ?grant_type=ig_exchange_token
  &client_secret={instagram-app-secret}
  &access_token={short-lived-access-token}

This will give a 60 days access token

Source


Once you got the the long-lived token, you can make a GET requst from this endpoint: https://graph.instagram.com/me/media

Add the token:

../me/media?access_token={access-token}

You can add also these some of these fields:

.../me/media?fields=media_url,thumbnail_url, caption&access_token=access_token={access-token}



This should return a json file that include things you need to do the portfolio.


Keep in mind that the token lasts only for 60 days and you need to refeash it once this time is over: See this for more information

0

I've come across the same issue and I've gathered up my findings on a step-by-step guide. Here are the key points:

  1. You need to go and create an App on developers.facebook.com and generate a Long-lived token (there is no need for post requests. The token can be generated with the click of a button).
  2. To fetch the photos, you need to make more than one call to the API. One for fetching the photos' IDs and then, one separate call for each ID to get the actual data (permalink, image URL, caption, etc).
  3. There is a limit to the calls that you can make per hour, which, as I realized, can be easily reached on a site with moderate traffic. So, you have to somehow cache the results (on WordPress, I used a transient for that which seems to work fine).
  4. The token expires after 60 days and you need to refresh it on time for your app to keep working.

To make things easier for future implementations, I also made a small PHP function that takes care of all of the above (except the token generation). It will make the necessary calls, store the response in a transient which expires after an hour, and refresh the token, if it can be refreshed.

giorgos
  • 398
  • 2
  • 6