我正在尝试从poloniex.com中提取一些信息并粘贴到Google工作表中的某个范围,并在尝试设置值时遇到问题。我对此很陌生,无法判断问题是否与我对setValues如何工作的理解有关,或者是否与我将数据推入价格数组的方式有关。
function processPoloAPI() {
var sheet = SpreadsheetApp.openById('<insert sheet id here>')
var APIPullSheet = sheet.getSheetByName("APIPull");
APIPullSheet.getRange('A2:D19999').clearContent();
var url = "https://poloniex.com/public?command=returnChartData¤cyPair=USDT_BTC&start=1405699200&end=9999999999&period=86400"
var responseAPI = UrlFetchApp.fetch(url)
var parcedData = JSON.parse(responseAPI.getContentText());
var prices = new Array ();
prices.push(['Date', 'High', 'Low', 'Open','Close', 'Volume', 'QuoteVolume', 'WeightedAverage'])
for(var key in parcedData)
{
prices.push(parcedData[key]);
}
var length = prices.length
askRange = APIPullSheet.getRange(1, 1, length, 8);
askRange.setValues(prices);
}
答案 0 :(得分:1)
以下修改怎么样?
setValues()
的数据是二维数组。prices
为[[Date, High, Low, Open, Close, Volume, QuoteVolume, WeightedAverage], {date=1424304000, volume=46.27631267, high=244, low=225, weightedAverage=239.62777823, quoteVolume=0.19311748, close=244, open=225},,,
。如果要创建每行仅为顶行的键编号的数据,则必须从JSON数据中检索每个数字。这些修改点中反映的修改后的脚本如下所示。
function processPoloAPI() {
var sheet = SpreadsheetApp.openById('<insert sheet id here>')
var APIPullSheet = sheet.getSheetByName("APIPull");
APIPullSheet.getRange('A2:D19999').clearContent();
var url = "https://poloniex.com/public?command=returnChartData¤cyPair=USDT_BTC&start=1405699200&end=9999999999&period=86400"
var responseAPI = UrlFetchApp.fetch(url)
var parcedData = JSON.parse(responseAPI.getContentText());
var prices = new Array ();
prices.push(['Date', 'High', 'Low', 'Open','Close', 'Volume', 'QuoteVolume', 'WeightedAverage'])
var keys = ['date', 'high', 'low', 'open', 'close', 'volume', 'quoteVolume', 'weightedAverage'];
for (var i in parcedData) {
var temp = [];
for (var j in keys) {
temp.push(parcedData[i][keys[j]]);
}
prices.push(temp);
}
var length = prices.length
askRange = APIPullSheet.getRange(1, 1, length, 8);
askRange.setValues(prices);
}
如果我误解了你的问题,我很抱歉。