I would like to create an apps script in a google docs spreadsheet that will periodically copy rows from the sheet and insert them into a fusion table. Below I've pasted my best attempt, but it should be noted that I really want it to be posting a 2 column range, not that pair of values. That is just a placeholder.
This link here describes how to talk to fusion tables http://code.google.com/apis/fusiontables/docs/developers_guide.html#Inserting
But I dont understand how to write the script to achieve this. I've messed around with it a bunch and I think I have these problems
-I'm not forming the post request correctly -I'm missing some sort of authentication step.
I am a total newb and what I have here is copy pasted. A few resources that looked helpful:
This guy seems to have figured out how to write an app script to send post requests http://blog.vivekhaldar.com/post/428652690/google-apps-script-spreadsheets-mashup-hub
This seems to be important
http://code.google.com/googleapps/appsscript/class_urlfetchapp.html
these people seem to be doing somthing very similiar, but I cant figure out how to make it work
http://groups.google.com/group/fusion-tables-users-group/browse_thread/thread/99db4db33e405f01
function deet() {
var advancedArgs = {
method: "post",
payload: "?sql=" + "INSERT INTO 1299801(Text, Number) VALUES ('Blue Shoes', 50)",
headers: {"Authorization": "Basic <base64 encoding of your username:passwd"}};
var response = UrlFetchApp.fetch(
"https://www.google.com/fusiontables/api/query",advancedArgs);
}
Thanks in advance!
Here's an updated version of a script that John McGrath via the Google Fusion Tables group authored to create a manual "sync" between a Google spreadsheet and a Google Fusion Table.
I've modified the script a bit for my needs and have added use of an API key and the new Fusion Tables API endpoint as the original version used the SQL API endpoint, which is being phased out.
To use, simply add your Fusion Table's encrypted table ID to the top of the script...
And add your api key...
This script wipes a Fusion Table and updates it with data from the first sheet in the spreadsheet. You need to create a named range (called "namedRange" but you can change this in the code). The row above the named range should be the headers. You also need to set the Table ID of the Fusion table you want to update, and you need to make sure the header names match the column names in the Fusion Table.
The script is a bit crude and lacks comments, but hopefully it will help you.