How I retrieved 13,000 Instagram Posts from Mauritius Instagram Influencers

The starting point was a list of local influencers featured in a blog post. I then asked the social media professionals from Digital Marketing Mauritius to verify and add other influencers. 

By Jason Bholanauth

While there exists several Paid and free tools to analyse your social media performance, some hard coded scripts can also help you retrieve substantial amount of information to gear your marketing efforts. 

Below is a script, initially from GitHub, which I used to retrieve over 13,000 content entries on Instagram to do an analysis of top influencers in Mauritius. 

How to use the script?

Step 1: Create a Google Spreadsheet;
Step 2: Go to Tools > Script Editor > Paste the script below;
Step 3: Edit both the Sheet name and the Instagram handle;
Step 4: Click on Run

If everything is setup well, you will start seeing the post in. 

 // the name of the sheet within your document
 var sheetName = “Sheet1”; Edit this to include your Sheet name
 // the name of the Instagram account you want to track
 var instagramAccountName = “username”; Edit to include the Instagram handle.
 function insertFollowerCount() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheetByName(this.sheetName);
 accountdata = getInstagramData(this.instagramAccountName);
 sheet.appendRow([Utilities.formatDate(new Date(), “GMT”, “yyyy-MM-dd”), accountdata.followerCount, accountdata.followCount, accountdata.mediaCount,accountdata.totalLikes, accountdata.totalComments, accountdata.EngagementRatio]);
 //if you want to use another timezone, you can adjust the timezone by using GMT+01:00 , GMT+06:00, GMT-06:00 …
 function getInstagramData(username) {
 var r = new RegExp(‘<script type=”text\/javascript”>’ +
 ‘([^{]+?({.*profile_pic_url.*})[^}]+?)’ +
 var url = “https://www.instagram.com/” + username, totalComments = 0, totalLikes = 0;
 var ignoreError = {
 var source = UrlFetchApp.fetch(url).getContentText();
 var jsonStr = source.match(r)[2];
 var data = JSON.parse(jsonStr);
 console.log(‘data’, data);
 var oldVariantOfData = data[‘entry_data’][‘ProfilePage’][0];
 console.log(‘oldVariantOfData’, oldVariantOfData);
 for(var i = 0; i < 12; i++) {
 totalComments += parseInt(oldVariantOfData.graphql.user.edge_owner_to_timeline_media.edges[i].node.edge_media_to_comment.count);
 for(var l = 0; l < 12; l++) {
 totalLikes += parseInt(oldVariantOfData.graphql.user.edge_owner_to_timeline_media.edges[l].node.edge_liked_by.count);
 return {
 followerCount : oldVariantOfData.graphql.user.edge_followed_by.count,
 followCount : oldVariantOfData.graphql.user.edge_follow.count,
 mediaCount : oldVariantOfData.graphql.user.edge_owner_to_timeline_media.count,
 totalComments : totalComments,
 totalLikes : totalLikes,
 EngagementRatio : (((totalLikes+totalComments))/oldVariantOfData.graphql.user.edge_followed_by.count)/12