Forked from nickboyce/instagram_count_to_googe_sheet.js
Created
November 26, 2018 00:30
-
-
Save sebasoffia/e4dd050df9079ec06d2b5e5ba66f870f to your computer and use it in GitHub Desktop.
Track your Instagram followers over time with Google Sheets Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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