-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstagram-followers.gs
31 lines (28 loc) · 1.23 KB
/
instagram-followers.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function initFollowerCount() {
// sets up sheet names and Instagram accounts
insertFollowerCount("sheet1", "profile1");
insertFollowerCount("sheet2", "profile2");
}
function insertFollowerCount(sheetName, instagramAccountName) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
accountdata = getInstagramData(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
};
}