Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sebasoffia/e4dd050df9079ec06d2b5e5ba66f870f to your computer and use it in GitHub Desktop.
Save sebasoffia/e4dd050df9079ec06d2b5e5ba66f870f to your computer and use it in GitHub Desktop.
Track your Instagram followers over time with Google Sheets Scripts
// the name of the sheet within your document
var sheetName = "Sheet1";
// the name of the Instagram account you want to track
var instagramAccountName = "kingandmcgaw";
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]);
};
function getInstagramData(username) {
var r = new RegExp('<script type="text\/javascript">' +
'([^{]+?({.*profile_pic_url.*})[^}]+?)' +
'<\/script>');
var url = "https://www.instagram.com/" + username
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);
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
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment