Skip to content

@chrislkeller /README.md
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP
SpreadSheet To Fusion Tables

Script to sync a Google SpreadSheet to a Fusion Table

I will admit that save for a few legacy projects that still use Fusion Tables I don't actively use this script anymore -- hence no real development or maintaining of it.

Something changed on the authentication end a while back it seems, and I can't vouch for whether this script continues to work or not. I know that once I enabled two-factor authentication for my Google account this script stopped working.

I've added a couple potential solutions here, but would welcome someone -- Google or otherwise -- to offer a long-term maintained solution.

Thanks goes out to John McGrath who did the bulk of the work in making this script happen.

  • Head to Google docs, create a spreadsheet and add some data to it. Simple enough right? Just make sure that Column A has data in it. It seems blank or null values will break the update function. Though if other columns are without data the script appears to work fine. At some point, I'll learn to add an error message if Column A is blank, but for now, Column A wants data.

Google spreadsheet

  • Now I'm going to create a Fusion Table based off my spreadsheet. I do this either by importing from Google Docs or downloading the spreadsheet as a csv and uploading it to Fusion Tables. It is important to note from the outset that the column names must match between the spreadsheet and the table. Remember, if you change a column name or add a column to the spreadsheet, be sure to change it/add it to the Fusion Table as well. For good measure I make sure any new columns are also in the same order.

Fusion Table Import

  • After my Fusion Table is created, I need to get the Encrypted Table ID in order to make sure the spreadsheet can access it. To find the Encrypted Table ID I click File --> About this table. I'll copy this somewhere in a text file until I need it.

  • I'm almost ready to make this happen, but I'm going to need one other piece of information - a Google Fusion Tables API key. I need to turn on access to the Fusion Tables API in Google's API console, and get an authentication key. Don't worry, this is much easier than it sounds.

  • First, head to the API Console dashboard and log in with your Google account if prompted. The first screen you see if an overview. If it's your first time here, you might not see a lot. On the left-side of the screen you'll see a dropdown where you can create a new project. Go ahead and create one and give it a name.

Fusion Table Import

  • Next click on Services on the left-side of the screen and you will see a heck of a lot of toggles that can turn on various Google APIs. Scroll down a bit until you find Fusion Tables API, and flip to toggle to the 'On' position.

Fusion Table Import

  • Finally, click on API Access on the left-side of the screen. You will see two main areas: Authorized API Access and Simple API Access. We're interested in the API Key shown under Simple API Access. I'll copy this somewhere in a text file next to my Encrypted Table ID.

Fusion Table Import

  • Now we're ready to add our script to our spreadsheet. Back at your spreadsheet, go to Tools --> Script Editor and paste the script code. I add my Fusion Table's encrypted table ID to the top of the script...

    // Add the encrypted table ID of the fusion table here
    var tableIDFusion = '17xnxY......';
    
  • Then I add my API key.

    // key needed for fusion tables api
    var fusionTablesAPIKey = '17xnxY......';
    
  • Click save. You will be prompted to give the project a name. "Update Fusion Tables" works. Click the save icon or go to File --> Save.

  • Reload the spreadsheet and you will see a new menu item next to help. Mine says "Data Update Functions." Click the menu item and you will see three options, though the names may differ at this point: "Change Range of Data to be Sent (Include Headers)", "Update Fusion Table" & "Change Email Information."

  1. First choose "Change Email Information." This will authenticate your gmail account to access the Fusion Table. Note: I HAVE NOT had success using this with a Google Apps account going to a private Gmail account. Click the couple of confirmation buttons that appear.

  2. Second you should select all of the data -- columns and rows -- you wish to sync and choose Change Range of Data to be Sent (Include Headers)". I usually just click the rectangle in the upper-left corner to sync everything. The beauty -- in my experience -- is that blank rows and columns can be synced but they won't be reflected on the Fusion Table. Click the two confirmation buttons that appear.

  1. Now just add some information to your spreadsheet and click "Update Fusion Table." Your spreadsheet data should be synced with your Fusion Table.

  1. Sit back and enjoy this moment …
I've also put together this working demo that I can grant you access to in case it helps you spot where a difference might lie. You can add your API key and Table ID to test things out, and then make a copy and be off and running. Just be sure you delete your API and Table IDs...

This script can now be combined with other script functions to make the integration between Google spreadsheets and Fusion Tables more powerful. Or perhaps you want to add a trigger to sync data between the spreadsheet and the table. Such a trigger can be added to run minute by minute, or hourly and those changes will be reflected on the table.

Of course, unless the script didn't work. Perhaps you received an error message like:

    Request failed for https://www.googleapis.com/fusiontables/v1/query?key=ajhdndna8282n29& returned code 403. Server response: { "error": { "errors": [ { "domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured" } ], "code": 403, "message": "Access Not Configured" } }
  1. So let's try to decipher some error messages.

If you get stuck and things just aren't working, let me know and I'll see what I can do. There are a lot of moving parts and little details to pay attention to, and I'm sure I've overlooked something in this walkthrough.

Trying to log error messages and the possible cause. These are not confirmed. Just best guesses

...

    Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyCBbVMnJwhD5xPYJpcvOT8vOUlLs9jYv5U& returned code 400. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (use muteHttpExceptions option to examine full response)

The following is likely caused by your API key not being recognized.

    Request failed for https://www.googleapis.com/fusiontables/v1/query?key=MY API CODE& returned code 401. Truncated server response: { "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "head... (use muteHttpExceptions option to examine full response) (line 79, file "Code")

Which might just mean that your API key isn't active yet… Or you might receive an error because you didn't authenticate with the application when prompted. Be sure you have activated the Fusion Tables API on the Google API console and added the key to the script in the proper place.

The following is likely caused by either not authenticating or a corrupt authentication token

    Request failed for https://www.google.com/accounts/ClientLogin returned code 403. Truncated server response: Error=BadAuthentication Url=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbutVGIXKvt9Nhj84zteA6Qk3RgCkgkQzOPygJE4aWgRrWXJ8_N... (use muteHttpExceptions option to examine full response

To sync things, Google needs to know you have permission to access the spreadsheet and Fusion Table. This is usually done by signing in the first time you run Update Fusion. It seems that this may have changed since this script was first created. A quick test showed that if I cleared out my email and password each time I ran the updateFusion function I was able to sync the spreadsheet. While not ideal, it seems to work.

To do this I added UserProperties.deleteAllProperties(); to the top of the updateFusion function, which I think starts around line 26.

The full function would looks like this:

    // main function
    function updateFusion() {

        UserProperties.deleteAllProperties();

        // gets the user property 'email' out of project properties
        var email = UserProperties.getProperty('email');

        // gets the user property 'password' out of project properties
        var password = UserProperties.getProperty('password');

        // if either email or password is not saved in project properties this will store them there

        if (email === null || password === null) {

            // browser box to input email
            email = Browser.inputBox('Enter email');
            password = Browser.inputBox('Enter password');
            UserProperties.setProperty('email', email);
            UserProperties.setProperty('password', password);
        } else {
            email = UserProperties.getProperty('email');
            password = UserProperties.getProperty('password');
        }

        var authToken = getGAauthenticationToken(email, password);
        deleteData(authToken, tableIDFusion);
        var updateMsg = updateData(authToken, tableIDFusion);
        var updatedRowsCount = updateMsg.split(/\n/).length - 2;
        SpreadsheetApp.getActiveSpreadsheet().toast("Updated " + updatedRowsCount + " rows in the Fusion Table", "Fusion Tables Update", 5)
    }; 
// Add the table ID of the fusion table here
var tableIDFusion = '17xnxY......';
// key needed for fusion tables api
var fusionTablesAPIKey = 'A2crr4Y......';
// the name of the range used in the program
var rangeName = 'updateFusion';
// create menu buttons
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [{
name: "Change Range of Data to be Sent (Include Headers)",
functionName: "setRangeFusion"
}, {
name: "Update Fusion Table",
functionName: "updateFusion"
}, {
name: "Change Email Information",
functionName: "fixEmail"
}];
ss.addMenu("Data Update Functions", menuEntries);
};
// main function
function updateFusion() {
UserProperties.deleteAllProperties();
// gets the user property 'email' out of project properties
var email = UserProperties.getProperty('email');
// gets the user property 'password' out of project properties
var password = UserProperties.getProperty('password');
// if either email or password is not saved in project properties this will store them there
if (email === null || password === null) {
// browser box to input email
email = Browser.inputBox('Enter email');
password = Browser.inputBox('Enter password');
UserProperties.setProperty('email', email);
UserProperties.setProperty('password', password);
} else {
email = UserProperties.getProperty('email');
password = UserProperties.getProperty('password');
}
var authToken = getGAauthenticationToken(email, password);
deleteData(authToken, tableIDFusion);
var updateMsg = updateData(authToken, tableIDFusion);
var updatedRowsCount = updateMsg.split(/\n/).length - 2;
SpreadsheetApp.getActiveSpreadsheet().toast("Updated " + updatedRowsCount + " rows in the Fusion Table", "Fusion Tables Update", 5)
};
// Google Authentication API this is taken directly from the google fusion api website
function getGAauthenticationToken(email, password) {
password = encodeURIComponent(password);
var response = UrlFetchApp.fetch("https://www.google.com/accounts/ClientLogin", {
method: "post",
payload: "accountType=GOOGLE&Email=" + email + "&Passwd=" + password + "&service=fusiontables&Source=testing"
});
var responseStr = response.getContentText();
responseStr = responseStr.slice(responseStr.search("Auth=") + 5, responseStr.length);
responseStr = responseStr.replace(/\n/g, "");
return responseStr;
};
// query fusion API post
function queryFusionTables(authToken, query) {
// location to send the infomation to
var prefix = "https://www.googleapis.com/fusiontables/v1/query?key=";
var suffix = fusionTablesAPIKey + '&';
var URL = prefix + suffix;
// sends the the authentication and the query in url format
var response = UrlFetchApp.fetch(URL, {
method: "post",
headers: {
"Authorization": "GoogleLogin auth=" + authToken,
},
payload: "sql=" + query
});
return response.getContentText();
};
// delete old data in fusion table
function deleteData(authToken, tableID) {
var query = encodeURIComponent("DELETE FROM " + tableID);
return queryFusionTables(authToken, query);
};
// puts all the current information in the spreadsheet into a query
function updateData(authToken, tableID) {
//find sheets with ranges that will be sent
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRangeByName(rangeName);
var data = range.getValues();
// format data
for (var i in data) {
for (var j in data[i]) {
if (isNaN(data[i][j])) {
data[i][j] = data[i][j].replace(/'/g, "\\'");
}
}
}
var headers = data[0];
//var queryPrepend = "INSERT INTO " + tableID + " (" + "\'" + headers.join("\',\'") + "\'" + ") VALUES ('";
var queryPrepend = "INSERT INTO " + tableID + " (" + headers.join(",") + ") VALUES ('";
var query = "";
for (var i = 1; i < data.length; ++i) {
if (typeof (data[i][0]) == "string" && data[i][0] == "") {
continue;
}
query += queryPrepend + data[i].join("','") + "'); ";
}
return queryFusionTables(authToken, encodeURIComponent(query));
};
// change email if needed
function fixEmail() {
var decision = Browser.msgBox("WARNING", "Are you sure you want to change your email?", Browser.Buttons.YES_NO);
if (decision == 'yes') {
var email = Browser.inputBox('Enter email');
var password = Browser.inputBox('Enter password');
UserProperties.setProperty('email', email);
UserProperties.setProperty('password', password);
}
};
// set range
function setRangeFusion() {
var decision = Browser.msgBox("WARNING", "Are you sure you want to change the Update Fusion Range?", Browser.Buttons.YES_NO);
if (decision == 'yes') {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var check = ss.getRangeByName(rangeName)
if (check != null) {
ss.removeNamedRange(rangeName);
}
var range = SpreadsheetApp.getActiveRange()
ss.setNamedRange(rangeName, range);
Browser.msgBox("WARNING", "The range \'" + rangeName + "\' used to send data to Fusion has been changed.", Browser.Buttons.OK);
}
};
@marcomow

Hey, thanks for the awesome job!!!

I'd suggest you to change line 114 with

var queryPrepend = "INSERT INTO " + tableID + " (" + headers.join(",") + ") VALUES ('";

Because to me was causing error 400, because it couldn't formulate the query.
So, just without putting quotemarks on headers (eg. instead of 'Header', Header), it run.

Again thanks for the awesome template, let me know what you think about this edit! :D

@chrislkeller

Three months later I remembered you added this. Thank you.

Adjustment made at line 114. I left the original in for a spell in case.

Chris K.

@heshow

Hello!

I have been looking for something like this for a long time!! Thanks Guys

I have one issue with the updateFusion function though

when I run the updateFunction I get the following error:

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=MY API CODE& returned code 401. Truncated server response: { "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "head... (use muteHttpExceptions option to examine full response) (line 79, file "Code")

and this what i have in line 79:

var response = UrlFetchApp.fetch(URL, {
method: "post",
headers: {
"Authorization": "GoogleLogin auth=" + authToken,
},
payload: "sql=" + query
});
return response.getContentText();
};

I would really appreciate it if you could please spear me your time and let me know what I am doing wrong?

Thank you

Heshow

PS - It seems like the delete query works because when I run the code it deletes the existing data in Google Fusion Table but it doesn't insert new data into the GF table from the Gsheet.

@aalvaradobarajas

Hi, can you help me?

this happens to my script:

Error en la solicitud para el código devuelto 400 de https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyAU1k1r_YbMVKVyBDzEGPHhG_aJG7Dmd-4&. Respuesta del servidor truncada: { "error": { "errors": [ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (usar la opción muteHttpExceptions para examinar toda la respuesta)

Thanks

@nizamiogni

I've got the same error as aalvaradobarajas.
Any suggestions?

@nizamiogni

The case is that I have more than 3 coloumns..

@jacovdmerwe

Hi and Thank you very much. I appreciate your effort and sharing. I am unsuccessful though to update to fusion tables and reveive the following error code:

Request failed for https://www.google.com/accounts/ClientLogin returned code 403. Truncated server response: Error=BadAuthentication Url=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbutVGIXKvt9Nhj84zteA6Qk3RgCkgkQzOPygJE4aWgRrWXJ8_N... (use muteHttpExceptions option to examine full response)

Could you kindly help me to fix this.
Regards
Jaco

@jacovdmerwe

Hi
I have resolved the above issue thank you. I discoverd that I did not read all your instructions thorougly enough and the issue was due to certein cells in column A being empty. But now I have another error code. Please help with this one:

@jacovdmerwe

Sorry about the above going through before I finished, I accidentally hit the enter key. Well, here is the error code below:

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyBZ7cNowvyJtmJFUTuWy-trvOb_aKkz_cE& returned code 400. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (use muteHttpExceptions option to examine full response)

What it does is delete all my table data already there, but then it does not update anything and gives the error above.

@MorgrimX

All but the update function worked.

"Request failed for https://www.google.com/accounts/ClientLogin returned code 403. Truncated server response: Error=BadAuthentication Url=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuxBXbcxmpYifEqDDgyv9RNMHVqos-u7nz2EtXDH4YaDo_EWdY... (use muteHttpExceptions option to examine full response)"

Any suggestions?

@MorgrimX

After ensuring column A in the table had no blank entry, I got the same error message shown in my previous entry above.

@chrislkeller
Owner

All... I'll see if I can't figure out the source of some of these errors and figure out what might be causing them and add them above.

I see the same ones over and over again as folks try to work through the moving parts, and I guess I should have been keeping an inventory.

UPDATE: So it seems I was able to overcome the BadAuthentication error that MorgrimX and jacovdmerwe mentioned.

    Request failed for https://www.google.com/accounts/ClientLogin returned code 403. Truncated server response: Error=BadAuthentication Url=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbutVGIXKvt9Nhj84zteA6Qk3RgCkgkQzOPygJE4aWgRrWXJ8_N... (use muteHttpExceptions option to examine full response

The solution isn't ideal, but an ideal solution would mean re-working some authentication things that I can't do right now.

To sync things, Google needs to know you have permission to access the spreadsheet and Fusion Table. This is usually done by signing in the first time you run Update Fusion. It seems that this may have changed since this script was first created. A quick test showed that if I cleared out my email and password each time I ran the updateFusion function I was able to sync the spreadsheet. While not ideal, it seems to work.

To do this I added UserProperties.deleteAllProperties(); to the top of the updateFusion function, which I think starts around line 26.

The full function would looks like this:

    // main function
    function updateFusion() {

        UserProperties.deleteAllProperties();

        // gets the user property 'email' out of project properties
        var email = UserProperties.getProperty('email');

        // gets the user property 'password' out of project properties
        var password = UserProperties.getProperty('password');

        // if either email or password is not saved in project properties this will store them there

        if (email === null || password === null) {

            // browser box to input email
            email = Browser.inputBox('Enter email');
            password = Browser.inputBox('Enter password');
            UserProperties.setProperty('email', email);
            UserProperties.setProperty('password', password);
        } else {
            email = UserProperties.getProperty('email');
            password = UserProperties.getProperty('password');
        }

        var authToken = getGAauthenticationToken(email, password);
        deleteData(authToken, tableIDFusion);
        var updateMsg = updateData(authToken, tableIDFusion);
        var updatedRowsCount = updateMsg.split(/\n/).length - 2;
        SpreadsheetApp.getActiveSpreadsheet().toast("Updated " + updatedRowsCount + " rows in the Fusion Table", "Fusion Tables Update", 5)
    }; 
@MorgrimX

I just noticed that Google was auto-emailing me about a suspicious Client login. I followed their suggestions. After indicating I was the one trying the login, I was taken to a page that said simply to try it again. I did, and I happily got past the client login error and now have an Invalid Query:

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyD2jIZ2OWM3_5DTWFuaSU4JZmB2hnhve78& returned code 400. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (use muteHttpExceptions option to examine full response)

I don't see where or how I can use muteHttpExceptions option. do you?

Also, I noticed on line 77 you are appended an ampersand to the end of the fusion table API key. That shows up in the error message. It strikes me as odd.

P.S. thank you for your quick response. the web page suggests you haven't been here for over a month, which seems very misleading.

@MorgrimX

Nagging issue. I am able to manually add (all) rows from my spreadsheet to my (emptied) fusion table with no problem. I am troubled, though, because my spreadsheet actually contains 7sheets. The addmenu() code adds a menu item to each sheet even though we intend to use it for only one sheet. Is that an issue with your code. Should there be only one sheet? Does it even make a difference as long as I select Update Fusion table when I'm using the intended sheet.

I just notice the Get Active Spreadsheet function, so I presume it works for the correct sheet.

@nidhasharna

Did anyone found solution to the Bad Query request. This is what I am getting.
{
"error": {
"errors": [
{
"domain": "fusiontables",
"reason": "badQueryCouldNotParse",
"message": "Invalid query: Parse error near 'null' (line 0, position -1).",
"locationType": "parameter",
"location": "q"
}
],
"code": 400,
"message": "Invalid query: Parse error near 'null' (line 0, position -1)."
}
}

Any help would be highly appreciated.

@marketymark

Hello,

My website is located here: http://www.geographyofpizza.com/home

As, you can see I am collecting geographic data and have a Google Form linked to a Fusion Table. This website originally helped me and it has been recently updated http://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesFormSync/docs/reference.html to incorporate the API. I followed the complete directions using this code here:http://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesFormSync/src/formsync.js and am still having issues similar to the previous comments in this thread of the Bad Query request:

Truncated server response: {
"error": {
"errors": [
{
"domain": "fusiontables",
"reason": "badQueryCouldNotParse",
"message": "Invalid query: Column `\"Othe... (use muteHttpExceptions option to examine full response)

I tried to incorporate: UserProperties.deleteAllProperties(); to see if that works and had no luck. Does anyone have any suggestions to get this Google Form to Sync With my Fusion Table?

Any help would be greatly appreciated :)

@jcardi

Hello, I'm a user of this great amazing script, which worked for me as recently as July 23. I'm now getting this error, which seems similar to others. Is there any solution??

I hope so, thank you so much!!

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyC766K5_Hwgzvs...asTAoNS7k& returned code 400. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (use muteHttpExceptions option to examine full response)

@nidhasharna

Can some one help, please. Stuck with that error from long :(

@frank984

I have a similar problem:

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyAijL_MG8Wp1YDP98JFlJFNQUS-cq6ShLE& returned code 400. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (use muteHttpExceptions option to examine full response)

@MorgrimX

I have not solved my bad authentication error that I reported above many months ago. So, I have been doing an update manually. I believe I understand why the update is failing on the fusion table.

After loading the data, I then manually summarized the data. I update the data manually every day. I delete all of the rows and reload data from my source spreadsheet. The option to delete all rows is greyed out and not available as long as the data summarize function is in effect. So, I learned quickly that I first had to go into the Summarize function and select the "Clear Summary" button.

After doing that I am able to delete all rows and then import more rows.

I can't automate this since I have no idea where one finds the fusion table commands to accomplish the Clear Summary, Delete all rows, and import new rows functions.

This, I believe, is at the heart of a lot of error comments here and should be explored.

@neilhawkins

Google is not allowing authentication and sending emails warning of suspicious login attempts originating from Mountain View(!) when I run the script. Bit stumped about how to get around this at the moment...

@chrislkeller

Apologies for all the unanswered questions and the lack of response from me on those questions.

I didn't know gists doesn't offer an email notification when a comment is made and I haven't checked here in a while.

Something changed on the authentication end a while back it seems, and I can't vouch for whether this script continues to work or not. I know that once I enabled two-factor authentication for my Google account this script stopped working.

I will admit that save for a few legacy projects that still use Fusion Tables I don't actively use this script anymore -- hence no real development or maintaining of it.

So what to do?

  • If you've been able to make this script work, awesome. Congrats.
  • If you haven't, I apologize. I've tried to document how I made it work the best that I can, but obviously that is little consolation.
    • One potential solution might be this "Synchronizing a Google Form with a Fusion Table" walkthough. Now it uses a form and I haven't used it in a while but it might be a solution for those looking to get data to a Fusion Table.
    • It sounds like "there's now a native Fusion Tables service in Apps Script" which might offer some possibilities. I've only dabbled with it, but there is the potential there for someone to put a new script together.

I may try to make something work because I see a real need for some kind of solution to keep data in a Google spreadsheet and a Google Fusion table synced.

@sheeloo

Solution to problem;
[ { "domain": "fusiontables", "reason": "badQueryCouldNotParse", "message": "Invalid query: Parse error ne... (use muteHttpExceptions option to examine full response)

I discovered that I was getting the error mentioned above if I had spaces in my column names. One needs to put single quotes around such column names.

To do this add the following loop [in function updateData(authToken, tableID)]
for (var i in headers) {
headers[i] = "'" + headers[i] + "'";
}
after the statement
var headers = data[0];

Thanks chrislkeller for a wonderful solution and explanation.

@Shellyhfettes

I have the error
Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyBNpeTYvF66WtJyLiVkqYWea9XQF_CrFPI& returned code 403. Truncated server response: { "error": { "errors": [ { "domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured. Please us... (use muteHttpExceptions option to examine full response).
I have never use API or fusion tables before, so dont know what to do.

Regards

Shelly

@lachelt

I got past the badQueryCouldNotParse problem.
Now the script deletes my table contents, and gives this error:

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyA82xLv8imBsHcIuSGLzGTzTQv7okXsue8& returned code 503. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "serverError", "message": "Internal error. Please try again." }... (use muteHttpExceptions option to examine full response)

And suggestions would be appreciated.

@golfecholima

Has anyone gotten a "Range not found." error message after trying to change the range?

@wstacey

To get past the "Range not found" error i commented out the

var check = ss.getRangeByName(rangeName)
if (check != null) {
ss.removeNamedRange(rangeName);
}

Line from the setRangeFusion() function, after you run it once (and that "rangeName" actually gets set) you can uncomment that line.

However i'm also running into the

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyA82xLv8imBsHcIuSGLzGTzTQv7okXsue8& returned code 503. Truncated server response: { "error": { "errors": [ { "domain": "fusiontables", "reason": "serverError", "message": "Internal error. Please try again." }... (use muteHttpExceptions option to examine full response) error message now.

@Cesare1

I had this report while debuging:

Request failed for https://www.googleapis.com/fusiontables/v1/query?key=AIzaSyAycTAhZp_LqIGvq4a8d-OjF_jkzIb1yzs& returned code 401. Truncated server response: { "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "head... (use muteHttpExceptions option to examine full response) (line 82, file "Code")

What should I do on line 82?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.