Using Google Spreadsheet to Update Fusion Table

只愿长相守 提交于 2019-12-23 05:35:16

问题


I am having an issue with code I am running in a spreadsheet that updates a fusion table. I run the following code (with the fusion table ID omitted for privacy).

 function updateFusion() {

    var tableIDFusion = '##############################'
    var email = UserProperties.getProperty('email'); 
    var password = UserProperties.getProperty('password');     
      if (email === null || password === null) {
        email = Browser.inputBox('Enter email');
        password = Browser.inputBox('Enter password'); 
        UserProperties.setProperty('email',email); 'email'
        UserProperties.setProperty('password', password); 
      }
      var authToken = getGAauthenticationToken(email,password); 
      deleteData(authToken, tableIDFusion); 
      updateData(authToken, tableIDFusion); 
      SpreadsheetApp.getActiveSpreadsheet().toast(Logger.getLog(), "Fusion Tables Update", 10) 
    }

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

I continue to get the error: Request failed for https://www.google.com/accounts/ClientLogin returned code 403. Server response: Error=BadAuthentication (line 97)

I understand coding but not much about servers and the way programs interact with each other and the code for my Formula Team's website has been passed to me and this is all a bit over my head and I am not sure what to do.

Any help is greatly appreciated!


回答1:


I've been using this version of a similar script. John McGrath via the Google Fusion Tables group brought it all together to create a manual "sync" between a Google spreadsheet and a Google Fusion Table.

I'm guessing they are similar, but perhaps you are missing some aspects?

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...

// Add the encrypted table ID of the fusion table here
var tableIDFusion = '17xnxY......';

And add your api key...

// key needed for fusion tables api
var fusionTablesAPIKey = '17xnxY......';


来源:https://stackoverflow.com/questions/14311840/using-google-spreadsheet-to-update-fusion-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!