Last active
August 24, 2018 20:49
-
-
Save mhawksey/9322ae8bb882e80cb686 to your computer and use it in GitHub Desktop.
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
This file contains hidden or 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 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