“Hack” your own Instagram — Ep.1 Instagram’s Inferred Interests

“Hack Your Own Instagram”

Its a late Friday night in the middle of April, a friend of mine has just brought revelation to my life. Apparently one can download data collected by Instagram and it comes in cutely organized folders.

I HAD TO EXPLORE, and I thought why note make a story for the journey one step at a time, I don’t know where this is going, but welcome to

Episode 1 : Instagram’s Inferred Interests

Head to you Instagram settings and head to the Privacy and Security tab

Head to you Instagram settings and head to the Privacy and Security tab
Go to the data download option and the rest should be quite straightforward

If you select ‘view account Data’ you can browse information collected cleanly on Instagram's front end. But that's boring so we will try to obtain this information ourselves. So we select ‘request download’ instead

list of folders found in the data folder

After downloading and extracting the file contents we observe the following well described folder titles. Some of them contain txt files, some of them contain photos (Be careful, you may find skeletons you have tried to bury) but most of the folders contain Json scripts. That is what we will try to make sense of today

* I AM STILL LOST ON HOW TO EMBED USABLE CODE HERE, BUT YOU CAN REFER TO GITHUB FOR A PROPER USABLE INDENTED VERSION OF THE CODE

Import the required modules

import pandas as pd
import numpy as np
import os
import json

I defined my own function to read the json files

## THIS FUNCTION TAKES IN THE FOLDER NAME OF INTEREST YOU HAVE CHOSEN AND THE CORRESPONDING JSON FILE YOU WANNA ACCESS
## AND ASSIGNS THE VALUES TO THE data variable
def read_my_data(folder_name_of_interest,folder_name_of_interest_contents):
with open(folder_name_of_interest + '/'+ folder_name_of_interest_contents) as json_file:
data = json.load(json_file)
return(data)

Check out the folders that exist

## Lets see all the folder names in the directory
folder_names_list = os.listdir()
display(folder_names_list)
you should observe a similar output

Pick the information about you folder and the ads_interests.json file inside that folder

## Lets try another 
folder_name_of_interest = 'information_about_you'
folder_name_of_interest_contents = os.listdir(folder_name_of_interest)
display(folder_name_of_interest_contents)
## here the folder name of interes contents actually has 2 files in it, i selected the ads_interest file thus index is [1]
data = read_my_data(folder_name_of_interest,folder_name_of_interest_contents[1])

Then just clean the data to make it neat and easy to read by doing the following

  1. Fill Na values with 0's
  2. remove rows with only white space values
  3. remove rows with 0's
  4. sort the data frame in alphabetical order

and finally save it into a csv file!

interests = [];
for i in range (0,len(data['inferred_data_ig_interest'])):
for key, value in data['inferred_data_ig_interest'][i]['string_map_data']['Interest'].items(): #accessing keys
# print(key,end=',')
# print(value,end='|')
interests.append(value)
display(interests)
### Do a lot of cleaning of the data and save it as a csv!
interests_df = pd.DataFrame(interests)
interests_df = interests_df.fillna(0)
interests_df = interests_df[interests_df[0]!='']
interests_df = interests_df[interests_df[0]!=0]
interests_df = interests_df.sort_values(0)
(interests_df).to_csv('infered_interests.csv',index=False)

I am proud to say, Instagram has inferred that I have an interest in Kesha

Guilty as charged,

This is where I try to use numbers to tell a story

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store