自动化的Instagram追踪器

时间:2019-03-11 16:35:13

标签: javascript google-sheets

// the name of the sheet within your document
var sheetName = "Sheet1
// the name of the Instagram account you want to track
var instagramAccountName = "username

function insert FollowerCount() {
  var ss = SpeadsheetApp.getActiveSpreadsheet
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,accountdata.totalLikes, accountdata.totalComments, accountdata.EngagementRatio]);  
 };
 
//if you want to use another timezone, you can adjust the timezone by using GMT+01:00 , GMT+06:00, GMT-06:00 ... 

function getInstagramData(username) {
  var r = new RegExp('<script type="text\/javascript">' + 
                   '([^{]+?({.*profile_pic_url.*})[^}]+?)' +
                   '<\/script>');
  var url = "https://www.instagram.com/" + username, totalComments = 0, totalLikes = 0;
  var ignoreError = {
   "muteHttpExcecptions":true
  };
  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);
 
    for(var i = 0; i < 12; i++) {
      totalComments += parseInt(oldVariantOfData.graphql.user.edge_owner_to_timeline_media.edges[i].node.edge_media_to_comment.count);
      Logger.log(totalComments);
       };
  
   for(var l = 0; l < 12; l++) {
          totalLikes += parseInt(oldVariantOfData.graphql.user.edge_owner_to_timeline_media.edges[l].node.edge_liked_by.count);
          Logger.log(totalLikes); 
        };
  
  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,
    totalComments : totalComments,
    totalLikes : totalLikes,
    EngagementRatio : (((totalLikes+totalComments))/oldVariantOfData.graphql.user.edge_followed_by.count)/12
  }  
}

这是我目前用于通过功能将instagram数据导入到Google表格中的功能,但是作为一个初学者,我不太确定如何为50多个instagram帐户执行此操作。我试图跟踪关注者,帖子,喜欢的人数,然后跟踪参与度。但是目前它一次只能在Google表格上运行一页,因此,我希望它可以从Google表格上的单独标签中拉出页面,谢谢。

理想格式

页面名称|链接到页面|日期|跟随者|跟随|总帖子|最近12个帖子的总赞|最近12个帖子的总评论|参与度

0 个答案:

没有答案