knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
library(ig)

ig

🖼 A minimal R client for interacting with Instagram's public API.

Installation

You can install {ig} from Github with:

devtools::install_github("mkearney/ig")

Authorization

To become authorized to interact with Instagram's API, users must first go here and create an Instagram app. Once you've created an app, copy the Client ID and Client Secret keys1 from the app's page and pass them along to ig_create_token().

## use client_id and client_secret to create and save access token
ig_create_token("pb112zgv5065tu60pxnqvp88f6hovbur", 
  "drz97x61d9s5g2nlcu87v63mdphiedcv")

It's not necessary to specify your token in each request (ig functions actually do that in the background for you), but if you'd like to view your access token, use ig_token().

## view your access token
ig_token()
#>                                         access_token 
#> "877861763.6001s28.4d8i211p0sf942o0394x5d4kwdk831l1" 

The rest of the token process is automated for you (you don't need to reference it again).

Endpoints

There are numerous API endpoints, but thanks to recent changes by Instagram, most users won't get access to large amounts of public data (at least not without first going through a strict submission process). Here are some that should still work though:

users/self

## get your instagram data
me <- ig_users_self()

## view data
ig_as_tbl(me)

users/self/media/recent

## get your media data
my_media <- ig_users_self_media_recent()

## view data
ig_as_tbl(my_media)

tags/{tags-name}

## get tags data
ig_tags <- ig_tags(tag = "metoo")

## view data
ig_as_tbl(ig_tags)

tags/search

## search tags data
ig_tags <- ig_tags_search(q = "metoo")

## view data
ig_as_tbl(ig_tags)

Additional endpoints

To send requests to additional endpoints, supply the path and any relevant query parameters to either ig_api_get() or ig_api_post().

## make custom request to locations/search endpoint
ig_locs <- ig_api_get("locations/search", lat = 48.858844, lng = 2.294351)

## view data
ig_as_tbl(ig_locs)

1 NOTE: All keys provided in examples are fake but are otherwise designed to appear similar to the actual keys assigned by Instagram.



mkearney/ig documentation built on May 8, 2019, 1:47 p.m.