Skip to content

Instantly share code, notes, and snippets.

@wrttnwrd
Created April 29, 2011 02:36
Show Gist options
  • Save wrttnwrd/947740 to your computer and use it in GitHub Desktop.
Save wrttnwrd/947740 to your computer and use it in GitHub Desktop.
Linkscape in Google Apps Script
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment