Linkscape in Google Apps Script

  • Download Gist
linkscape-google-apps-script.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
function getLinkscape() {
lastRow = FindRows();
startRow = lastRow + 1;
var active_spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var utility_sheet = active_spreadsheet.getSheetByName("Utilities");
params = utility_sheet.getRange(5,3,7,3).getValues();
url = params[2][0];
AccessID = params[0][0];
secret = params[1][0];
method = "HMAC_SHA_1";
uDate = new Date().getTime();
uDate = Math.round(uDate/1000);
Expires = uDate + 1200;
theString = AccessID + "\n" + Expires;
signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_1,theString,secret);
signature64 = Utilities.base64Encode(signature);
signature64 = encodeURIComponent(signature64);
inV="http://lsapi.seomoz.com/linkscape/url-metrics/" + url + "?AccessID=" + AccessID + "&Expires=" + Expires + "&Signature=" + signature64 + "&Cols=85899345920";
jsonStringResponse = UrlFetchApp.fetch(inV);
var data1 = jsonStringResponse.getContentText();
data2 = Utilities.jsonParse(data1);
IDomains = data2["fipl"];
Dauth = data2["pda"];
SpreadsheetApp.getActiveSheet().getRange(startRow,3).setValue(IDomains);
SpreadsheetApp.getActiveSheet().getRange(startRow,4).setValue(Dauth);
monthYear = utility_sheet.getRange(12,4).getValue();
today = monthYear;
SpreadsheetApp.getActiveSheet().getRange(startRow,2).setValue(today);
SpreadsheetApp.getActiveSheet().getRange(4,3).setValue(today);
// some quick formatting - adds border to the whole row
for (z=2; z<12; z++)
{
SpreadsheetApp.getActiveSheet().getRange(startRow,z).setBorder(true,true,true,true,true,true);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.