我在更新融合表的電子表格中運行的代碼存在問題。我運行下面的代碼(爲了保密,省略了融合表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網站的代碼已經傳遞給我了,這一切都在我頭上,我不知道該怎麼做。
任何幫助,非常感謝!
其實我剛認識約翰,他和我一起上課,我和他一起工作的代碼是他的。我們坐下來,經歷了遷移的東西,但我仍然有同樣的問題。我得到的錯誤發生在var響應下的getGAauthenticationToken函數中,遠早於queryFusionTables函數被調用之前。 另外,tableICFusion和fusionTablesAPIKey應該是不同的,對嗎? – user1975292
對於如此遲到的迴應我深表歉意。 是的,融合表ID和API密鑰是不同的。您需要從API控制檯獲取API密鑰:https://code.google.com/apis/console/ 您是否在電子表格中使用個人帳戶? 電子表格中的列是否與Fusion Table中的列完全相同並且順序相同? –