Skip to content

Instantly share code, notes, and snippets.

@BetoFrega
Created April 3, 2015 18:40
Show Gist options
  • Save BetoFrega/32d91c89aa88e7691d42 to your computer and use it in GitHub Desktop.
Save BetoFrega/32d91c89aa88e7691d42 to your computer and use it in GitHub Desktop.
count clicks bitly
function counterBitly() {
//Creating Variables
var access_token = "xxxxxxxxxxxxxxxxxxxx ";
var url= "https://api-ssl.bitly.com/v3/link/clicks?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 clicks = JSON.parse(content).data.link_clicks;
for(i in clicks)
{
var obj = clicks[i];
var published = new Date(1970,0,1);
published.setSeconds(obj.dt);
//Printing data in the SpreadSheet (clicks, published)
Logger.log(sheet.appendRow([obj.clicks,published]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment