Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Apps Script version for using import.io authenticated data sources http://blog.import.io/post/using-importio-authenticated-data-sources-with-php-and-go
function getResults() {
var connector = {'username':'YOUR_SITE_USERNAME',
'password':'YOUR_SITE_PASSWORD',
'connectorDomain':'YOUR_CONNECTOR_DOMAIN',
'userGuid':'YOUR_USER_GUID',
'connectorGuid':'YOUR_CONNECTOR_GUID',
'apiKey':'YOUR_API_KEY'}
var creds = {};
creds[connector.connectorDomain] = {
"username": connector.username,
"password": connector.password
};
var additionalInput = {};
additionalInput[connector.connectorGuid] = {'domainCredentials':creds};
//get cookies
var login = query(connector.connectorGuid, false, connector.userGuid, connector.apiKey, additionalInput, false);
additionalInput[connector.connectorGuid].cookies = login.cookies;
var result = query(connector.connectorGuid, {"webpage/url":"http://ocs.sfu.ca/alt/index.php/conferences/altc2015/director/submissionReview/799/1"}, connector.userGuid, connector.apiKey, additionalInput, false);
// do something with results like write to Google Sheet https://developers.google.com/apps-script/guides/sheets#writing_data
}
// http://blog.import.io/post/using-importio-authenticated-data-sources-with-php-and-go
function query(connectorGuid, input, userGuid, apiKey, additionalInput, login) {
var url = "https://api.import.io/store/connector/" + connectorGuid + "/_query?_user=" + userGuid + "&_apikey=" + apiKey;
var data = {};
if (input) {
data["input"] = input;
}
if (additionalInput) {
data["additionalInput"] = additionalInput;
}
if (login) {
data["loginOnly"] = true;
}
var ch = UrlFetchApp.fetch(url, {'method':'POST', 'payload': JSON.stringify(data)});
var result = ch.getContentText();
return JSON.parse(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment