我正在构建一个小脚本来导入直接从Google表格中的Facebook Api获取的Facebook数据。我已经能够在我的Google App脚本日志中成功验证并传递API调用的响应。但是,我真的不知道如何在我的工作表中实际传递这些数据。
以下脚本允许我记录来自fb api的数据:
function myFunction() {
var response = UrlFetchApp.fetch("https://graph.facebook.com/v2.3/page_id/insights/page_impressions?access_token=mytoken");
var json = response.getContentText(); //
var rawdata = JSON.parse(json);
var rawdata = Utilities.jsonParse(response.getContentText());
Logger.log(rawdata);
然后我认为我应该做的是使用push方法在新数组中推送我需要的数据:
var data = [];
data.push(rawdata.???) // don't really the name I need to access the data I want
SpreadsheetApp.getActiveSheet().appendRow(data)
}
我的问题:
由于我不知道如何阅读从facebook api获取的数据,我真的不知道如何在我的data
数组中推送它们。这是我日志的结果:
[16-11-21 10:01:33:622 PST] {data=[{period=day,
values=[{end_time=2016-11-17T08:00:00+0000, value=26023596},
{end_time=2016-11-18T08:00:00+0000,value=24447386},
{end_time=2016-11-19T08:00:00+0000, value=31057386}],
name=page_impressions, description=Daily: The number of impressions seen of any content associated with your Page. (Total Count),
id=page_id/insights/page_impressions/day,
title=Daily Total Impressions},
{period=week,
values=[{end_time=2016-11-17T08:00:00+0000, value=233007217},{end_time=2016-11-18T08:00:00+0000, value=200263630},
{end_time=2016-11-19T08:00:00+0000, value=194289364}],
name=page_impressions,
description=Weekly: The number of impressions seen of any content associated with your Page. (Total Count),
id=page_id/insights/page_impressions/week, title=Weekly Total Impressions},
{period=days_28, values=[{end_time=2016-11-17T08:00:00+0000, value=867302439},
{end_time=2016-11-18T08:00:00+0000, value=868201060}, {end_time=2016-11-19T08:00:00+0000, value=874965509}],
name=page_impressions, description=28 Days: The number of impressions seen of any content associated with your Page. (Total Count),
id=page_id/insights/page_impressions/days_28, title=28 Days Total Impressions}],
paging={next=https://graph.facebook.com/v2.3/page_id/insights/page_impressions?access_token=my_token,
previous=https://graph.facebook.com/v2.3/page_id/insights/page_impressions?access_token=my_token}}
如果需要一个示例来说明答案,请说我想要facebook给我的三天每日总展示次数。
我希望我的问题足够明确。不确定我应该使用哪个标签来解决这个问题。如果我错了,请纠正我。
谢谢!
答案 0 :(得分:1)
您需要决定将哪些数据推入数组然后放入工作表。我会先将您的原始日志文件放入JSON prettifier,以便轻松查看格式。然后,take a look at how to manipulate JSON使用应用脚本。