analyze instagram R

Analyze Instagram with R

analyze instagram R
This tutorial will show you how you create an Instagram app, create an authentication process with R and get data via the Instagram API.
There is no R package for this yet so we have to configure the authentication and data download process on our own. But Instagram offers a pretty good documented API and uses oAuth 2 which makes it easy to use with R and the httr package for example.


The place to start for everybody who wants to work with the Instagram API is
Here you can find all the information you need and also manage your apps.
So click on „Register Your Application“ and go through the login.
R analyze instagram
On the next screen you can set the parameters for your app. Choose an application name ,write a small description of what your app will be about and add a webiste
Then you have to enter an OAuth redirect URI. To choose it go to your R console and execute following code:
This will show you the preferred callback URI for httr. Copy this URL and paste it in your app settings.
This is how my settings look like:
Analyze instagram with R
After clicking on „Register“ you will be redirected your app authentication details we will need for our analysis.
In R we have to define 4 variables:
The first 3 you get from your app settings. The third on scope is basically the level of authorization you want to get. Basic is enough to download data like likes or comments. If you actually want to post something to Instagram you need another scope. You can find more information on the Instagram developer page about that.
Then we create our Instagram in R for the httr package. This is the app we will use to connect to the API. To do so we have to provide the access points.
In the next step we do the authentication
Now your browser should open and ask you to give permission to the app. After you returned to R you should have received your access token.

Our analysis focuses on analysing our own profile. Instagram is very restrictive when it comes to sandbox apps and they don´t return any other data than the data from your own profile.

Analyze Instagram with R

We can now download your most recent media items from Instagram.
This returns the recent 20 pictures of the user we will use for our analysis. We go through them with a for loop to extract the count of likes and comments and the date and time the photo was posted.
Instagram uses UNIX timestamps as their date. So we have to convert it to make it readable.


Now we can visualize the data. I will use the rCharts package to so. Of course you can also use ggplot2 or whatever package you like.

You can find the complete code of the tutorial on my github account:

Julian Hillebrand

During my time at university and learning about the basics of economics I started heavily exploring the possibilities and changes caused by digital disruptions and the process of digital transformation, whereby I focused on the importance of data and data analytics and combination with marketing and management.
My personal focus of interest lies heavily on technology, digital marketing and data analytics. I made early acquaintance with programming and digital technology and never stop being interested in following the newest innovations.

I am an open, communicative and curious person. I enjoy writing, blogging and speaking about technology.