I'm trying to add a row of data to a Fusion Table. Having trouble with OAuth it seems. I go through requesting for a token and receive one and store it. This is the code used to do this:
var AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/auth';
function getURLForAuth(){
return AUTHORIZE_URL + '?response_type=code&client_id='+CLIENT_ID+'&redirect_uri='+REDIRECT_URL +'&scope=https://www.googleapis.com/auth/fusiontables&state=/profile';
}
After allowing access on the google site page this code gives me a page from which I can take the token and store it. I then try to use this token to insert a few values into a table with this code:
function _submitLog(e){
var rowToAdd = [e.parameter.empName,e.parameter.jobName,e.parameter.taskName,e.parameter.hoursBox, e.parameter.date];
runSQL("INSERT INTO "+TABLE_NAME +" (logNum,EmployeeName,JobName,TaskName,Hours,Date) VALUES (" +"'" +e.parameter.empName +"'" +"," +"'"+e.parameter.jobName +"'"+"," +"'"+e.parameter.taskName+"'" +"," +"'"+e.parameter.hoursBox+"'" +"," +"'"+e.parameter.date+"'" +")")
}
function runSQL(sql){
var getDataURL = 'https://www.googleapis.com/fusiontables/v1/query?sql='+sql;
var dataResponse = UrlFetchApp.fetch(getDataURL,getUrlFetchOptions()).getContentText();
Logger.log(dataResponse);
return dataResponse;
}
function getUrlFetchOptions() {
var token = UserProperties.getProperty(tokenPropertyName);
Logger.log(token);
return {
"method" : "post",
"ContentType" : "application/json",
"headers":{"Authorization" :"Bearer "+token,
"Accept" :"application/json"}
};
}
Im Sure I'm missing something extremely obvious, but I've been staring for hours and can't come up with it. Any help, even about best practices which I have probably obliterated would be great.