2013-01-14 36 views
0

我在更新融合表的電子表格中運行的代碼存在問題。我運行下面的代碼(爲了保密,省略了融合表ID)。使用Google Spreadsheet更新Fusion表

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

我繼續得到錯誤: 請求失敗https://www.google.com/accounts/ClientLogin返回碼403服務器響應:錯誤= BadAuthentication(線97)

我明白編碼,但沒有太多的有關服務器的方式和程序進行交互彼此之間以及我的Formula Team網站的代碼已經傳遞給我了,這一切都在我頭上,我不知道該怎麼做。

任何幫助,非常感謝!

回答

0

我一直在使用這個類似腳本的versionJohn McGrath通過Google Fusion Tables小組將它們組合在一起,在Google電子表格和Google Fusion表格之間創建手動「同步」。

我猜他們是相似的,但也許你錯過了一些方面?

爲了滿足我的需求,我已經修改了一下腳本,並增加了API keynew Fusion Tables API endpoint的使用,原始版本使用了正在逐步淘汰的SQL API端點。

使用時,只需將融合表的加密表ID添加到腳本的頂部...

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

,並添加您api key ...

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

其實我剛認識約翰,他和我一起上課,我和他一起工作的代碼是他的。我們坐下來,經歷了遷移的東西,但我仍然有同樣的問題。我得到的錯誤發生在var響應下的getGAauthenticationToken函數中,遠早於queryFusionTables函數被調用之前。 另外,tableICFusion和fusionTablesAPIKey應該是不同的,對嗎? – user1975292

+0

對於如此遲到的迴應我深表歉意。 是的,融合表ID和API密鑰是不同的。您需要從API控制檯獲取API密鑰:https://code.google.com/apis/console/ 您是否在電子表格中使用個人帳戶? 電子表格中的列是否與Fusion Table中的列完全相同並且順序相同? –

相關問題