Google Sheets script

I have started a project where I will be adding my family and friends into spreadsheet posted on a website, tracking how many Instagram followers we gain each hour, each day, split into various sheets.

I want my website to have various sheets & charts with names & details, updated hourly, daily, weekly, monthly & yearly. So far this Google Sheet script only feeds the date & time but doesn’t replace. Does anyone know how to help?

Google Sheet script:

// 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
  }; 
}

Offtopic: When you post code, please use three backticks (the ` symbol, usually below the esc key on keyboards, next to the 1) or click the </> button in the editor to make the code render as code instead of plain text, making it easier for others to read.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.