Instantly share code, notes, and snippets.

Embed
What would you like to do?
//https://stackoverflow.com/questions/49812575/instagram-a-1-not-working-anymore
//https://medium.com/@nickboyce/how-to-track-your-instagram-followers-over-time-with-google-sheets-scripts-bd9f5acf5ede
// the name of the sheet within your document
var sheetName = "FollowerCount";
// the name of the Instagram account you want to track
var instagramAccountName = "ACCOUNTNAMEYOUWANTTOTRACK";
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]);
};
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