9

I am trying to show instagram feed(of a specific account) on website using the developer documentation at https://developers.facebook.com/docs/instagram-basic-display-api/getting-started . instagram-basic-display-api seems supporting "Getting an Instagram user’s images, videos, and albums".

Manually through browser I could get the Authorization code by clicking "Authorize" in the Authorization Window. But it's mentioned in the post that "Authorization codes are short-lived and are only valid for 1 hour.". And hence I couldn't reuse the same authorization code for all the requests and every hour I need to generate a new one. Is there a way or javascript sdk that allows to make the request through code(javascript) to generate authorization code without Authorization Window?

Avenger
  • 205
  • 2
  • 10

1 Answers1

4

Facebook will let you generate a CODE through the browser (GET). Then you will need to exchange mentioned CODE for a TOKEN, but now through cURL request (you can use POSTMAN, for example). as in Step 5: https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

If you're using Postman, make sure you put the required parameters in the body as x-www-form-urlencoded.

After Step 5 you may receive an access_token, which you will then be able to query the user. It's a short-lived TOKEN.

As for your question, you would then be able to exchange this short-lived token for a long-lived one, as in https://developers.facebook.com/docs/instagram-basic-display-api/guides/long-lived-access-tokens.

But there are some caveats:

  1. your app must be granted instagram_graph_user_profile
  2. the exchange should only be made in server-side code
  3. expired short-lived tokens cannot be exchanged
  4. long-lived tokens only last 60 days, they need to be refreshed once in a while
  5. if one expires, you can't refresh it
luiscabus
  • 199
  • 3
  • 8
  • Can one make HTTP requests rather than cURL requests to the new Basic Display API? How might one use the API on a serverless setup like Netlify? – Brendan Dec 22 '19 at 19:28
  • Basically you need to make a POST request to the api url, sending the parameters accordingly. Not very familiar with serverless, but that might have nothing to do with the matter. If ASP language, for example, one can use an MSXML2.ServerXMLHTTP object. – luiscabus Dec 23 '19 at 20:26