Created
April 3, 2015 18:40
-
-
Save BetoFrega/32d91c89aa88e7691d42 to your computer and use it in GitHub Desktop.
count clicks bitly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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