Ste*_*tep 12 javascript basic-authentication urlfetch google-apps-script
我在 Google Apps Script 中有以下代码,它使用基本身份验证通过 HTTP 从网页中检索 CSV 数据并将其放入电子表格中:
CSVImport.gs
function parseCSVtoSheet(sheetName, url)
{
// Credentials
var username = "myusername";
var password = "mypassword";
var header = "Basic " + Utilities.base64Encode(username + ":" + password);
// Setting the authorization header for basic HTTP authentication
var options = {
"headers": {
"Authorization": header
}
};
// Getting the ID of the sheet with the name passed as parameter
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName(sheetName);
var sheetId = sheet.getSheetId();
// Getting the CSV data and placing it into the spreadsheet
var csvContent = UrlFetchApp.fetch(url, options).getContentText();
var resource = {requests: [{pasteData: {data: csvContent, coordinate: {sheetId: sheetId}, delimiter: ","}}]};
Sheets.Spreadsheets.batchUpdate(resource, spreadsheet.getId());
}
Run Code Online (Sandbox Code Playgroud)
这一直在工作,直到最近我随机收到以下错误UrlFetchApp.fetch:
Exception: Unexpected error: http://www.myurl.com/data/myfile.csv (line 21, file "CSVImport")
我试过了:
我不知道还有什么要尝试的,以及为什么会突然突然崩溃。有什么建议吗?
| 归档时间: |
|
| 查看次数: |
1484 次 |
| 最近记录: |