Chapter 15 Instagram Graph API

Philipp Kadel

You will need to install the following packages for this chapter (run the code):

# install.packages('pacman')

15.1 Provided services/data

  • What data/service is provided by the API?

The Instagram Graph API is provided by Facebook. There are two main APIs for Instagram, the Instagram Basic Display API and the Instagram Graph API. The latter is described in the following.

The API can be used to get and manage published photos, videos, and stories as well as getting basic data about other Instagram Business users and Creators. It is also possible to moderate comments and their replies and to measure media and profile interaction. Photos and videos can be published directly from the API. It can also be used to discover hashtagged media and mentions.

For photos and videos different metrics can be obtained:

  • engagement – Total number of likes and comments on the media object.
  • Impressions – Total number of times the media object has been seen.
  • Reach – Total number of unique accounts that have seen the media object.
  • Saved – Total number of unique accounts that have saved the media object.
  • Video_views – (Videos only) Total number of times the video has been seen. Returns 0 for videos in carousel albums.

Likewise, there are several metrics about stories that are provided by the API:

  • Exits – Number of times someone exited the story.
  • Impressions – Total number of times the story has been seen.
  • Reach – Total number of unique accounts that have seen the story.
  • Replies – Total number of replies to the story.
  • Taps_forward – Total number of taps to see this story’s next photo or video.

15.2 Prerequisites

  • What are the prerequisites to access the API (authentication)?

For most endpoints you need an Instagram Business Account, a Facebook Page that is connected to that account, a Facebook Developer Account and a Facebook App with Basic settings configured. Facebook provides a tutorial for setting this up here.

15.3 Simple API call

  • What does a simple API call look like?

First of all you have to load the required httr package.


Below you can find expamples of simple API calls for the Instagram Graph API.

Get Fields and Edges on an IG Media. Fields can be e.g., “caption”, “comments_count”, “like_count”, or “timestamp”.




  "id": "17895695668004550",
  "media_type": "IMAGE",
  "media_url": "",
  "owner": {
    "id": "17841405822304914"
  "timestamp": "2017-08-31T18:10:00+0000"

Return Fields and Edges on an IG Hashtag. Field can be the name of the hashtag without the “#” symbol or a hashtag ID.




{ "id": "17841593698074073",
  "name": "coke" }

Get fields and edges on an Instagram Business or Creator Account. Fields can be e.g., “biography”, “id”, “followers_count”, or “media_count”.




{  "biography": "Dino data crunching app",
  "id": "17841405822304914",
  "username": "metricsaurus",
  "website": "" }

15.4 API access in R

  • How can we access the API from R (httr + other packages)?

The httr package can be used to access the Instagram Graph API. There used to be a instaR package but it was made for the old Instagram API and can not be used anymore. The FBinsightsR package provides access to the Insights API. Its fbins_insta function can be used to collect Instagram insights. Detailed information on the packages’ functions can be found here and more information on the deprecated instaR package here.

15.5 Social science examples

  • Are there social science research examples using the API?

In their study, Ferwerda, Schedl, and Tkalcic (2015) tried to infer personality traits from the way users take pictures and apply filters to them. The authors found distinct picture features (e.g., hue, brightness, saturation) that are related to personality traits. Brown et al. (2019) investigated the link between acute suicidality and language use as well as activity on Instagram. Differences in activity and language use on Instagram were not associated with acute suicidality. The goal of a study by Hosseinmardi et al. (2015) was to automatically detect and predict incidents of cyberbullying on Instagram. Based on a sample data set consisting of Instagram images and their associated comments, media sessions were labeled for cyberbullying. Associations are investigated between cyberbullying and a host of features such as cyber aggression, profanity, social graph features, temporal commenting behavior, linguistic content, and image content.


Brown, Rebecca C, Eileen Bendig, Tin Fischer, A David Goldwich, Harald Baumeister, and Paul L Plener. 2019. “Can Acute Suicidality Be Predicted by Instagram Data? Results from Qualitative and Quantitative Language Analyses.” PLoS One 14 (9): e0220623.
Ferwerda, Bruce, Markus Schedl, and Marko Tkalcic. 2015. “Predicting Personality Traits with Instagram Pictures.” In Proceedings of the 3rd Workshop on Emotions and Personality in Personalized Systems 2015, 7–10. EMPIRE ’15. New York, NY, USA: Association for Computing Machinery.
Hosseinmardi, Homa, Sabrina Arredondo Mattson, Rahat Ibn Rafiq, Richard Han, Qin Lv, and Shivakant Mishr. 2015. “Prediction of Cyberbullying Incidents on the Instagram Social Network,” August.