Skip to content

Instantly share code, notes, and snippets.

@BetoFrega
Created April 3, 2015 18:36
Show Gist options
  • Save BetoFrega/567fe498b0878b783c28 to your computer and use it in GitHub Desktop.
Save BetoFrega/567fe498b0878b783c28 to your computer and use it in GitHub Desktop.
Count likes and comments posts Instagram
function puxa() {
//Creating Variables
var userID = "xxxxxxxxxx";
var access_token = "yyyyyyyyyy";
var url= "https://api.instagram.com/v1/users/"+userID+"/media/recent?access_token="+access_token;
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet();
var sheet = ss.getActiveSheet();
var today = new Date();
sheet.setName(today)
//Performing Calculation
content = UrlFetchApp.fetch(url);
var posts = JSON.parse(content).data;
for(i in posts)
{
var obj = posts[i];
var published = new Date(1970,0,1);
published.setSeconds(obj.created_time);
//Printing data in the SpreadSheet (link / likes / published / comments)
Logger.log(sheet.appendRow([obj.link,published,obj.likes.count,obj.comments.count]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment