Google Fusion Tables API Sample Code

Google Apps Script Example

The following example demonstrates how to run the SHOW TABLES query in Google Spreadsheets using a Google Apps Script.

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;
}

function getdata(authToken, developerKey) {
  query = encodeURIComponent("SHOW TABLES");
  var URL = "https://www.googleapis.com/fusiontables/v1/query?key=" + developerKey + "&sql=" + query;
  var response = UrlFetchApp.fetch(URL, {
     method: "get",
     headers: {
          "Authorization": "GoogleLogin auth=" + authToken,
     }
  });
  return response.getContentText();
}