在facebook insights连接器

时间:2017-11-16 10:47:56

标签: facebook-insights google-data-studio

我正在编写一个在Google数据工作室中使用的facebook insights连接器,但在请求中使用指标 page_fans_city 时,我无法找到处理响应的正确方法。返回的数据具有以下格式:

{
  "data": [
    {
      "name": "page_fans_city",
      "period": "lifetime",
      "values": [
        {
          "value": {
            "Ancona, Marche, Italy": 61,
            "Arezzo, Tuscany, Italy": 42,
            "Bari, Puglia, Italy": 362,
            "Bergamo, Lombardia, Italy": 48,
            "Bologna, Emilia-Romagna, Italy": 388,
            "Brescia, Lombardia, Italy": 103,
            "Cagliari, Sardinia, Italy": 145,
            "Caserta, Campania, Italy": 64,
            "Catania, Sicilia, Italy": 272,
            "Ferrara, Emilia-Romagna, Italy": 50,
            ...
          },
          "end_time": "2017-11-13T08:00:00+0000"
        },
...
}

因为你可以看到"值"不是单个项目(数字或字符串),而是一个对象。我的数据模式包括:

  {
    name: 'city_name',
    label: 'City',
    dataType: 'STRING',
    semantics: {
      conceptType: 'DIMENSION'
    }
  },  
  {
    name: 'city_likes',
    label: 'Likes per City',
    dataType: 'NUMBER',
    semantics: {
      conceptType: 'METRIC'
    }
  }

在我的 getData(请求)函数实现中,我需要推送所有对城市名称 - 喜欢在特定时间范围内的每一天,所以我写道:

case 'city_name':
  var dataObj = response.data[1].values[0].value;
  var objKeys = Object.keys(dataObj);
  //pushing all the keys
  for (var n=0; n<objKeys.length; n++) {
    values.push(objKeys[n]);
  }
  break;

case 'city_likes':
  var dataObj = response.data[1].values[0].value;
  var objKeys = Object.keys(dataObj);
  //pushing all the values
  for (var n=0; n<objKeys.length; n++) {
    values.push(dataObj[objKeys[n]]);
  }                     
  break; 

但如果我使用这些维度/指标来构建表格,我会在数据工作室信息中心上遇到系统错误。有谁知道管理这种情况的正确方法?可能架构必须不同? 提前谢谢。

更新

这就是我目前发送的内容:

{
    schema=
    [
        {
            dataType=NUMBER, 
            name=city_likes, 
            label=Likes per City, 
            semantics=
            {
                conceptType=METRIC
            }
        }, 
        {
            dataType=STRING, 
            name=city_name, 
            label=City, 
            semantics=
            {
                conceptType=DIMENSION
            }
        }
    ], 
    rows=
    [
        {
            values=[62, 326, 78, 396, 130, 179, 73, 248, 48, 65, 450, 80, 47, 277, 57, 83, 85, 87, 82, 2065, 88, 901, 144, 466, 87, 140, 53, 102, 63, 89, 56, 81, 94, 85, 1992, 88, 71, 52, 98, 631, 50, 212, 164, 55, 49, Ancona, Bari, Bergamo, Bologna, Brescia, Cagliari, Caserta, Catania, Como, Ferrara, Florence, Foggia, Forlì, Genova, La Spezia, Lecce, Livorno, Lucca, Messina, Milan, Modena, Naples, Padua, Palermo, Parma, Perugia, Pesaro, Pescara, Pisa, Prato, Ravenna, Reggio di Calabria, Reggio nell Emilia, Rimini, Rome, Sassari, Taranto, Terni, Trieste, Turin, Udine, Venice, Verona, Vicenza, Vietri sul Mare]
        }
    ]
}

任何想法?

1 个答案:

答案 0 :(得分:0)

您的回答应该更像这样:

{
schema=
[
    {
        dataType=NUMBER, 
        name=city_likes, 
        label=Likes per City, 
        semantics=
        {
            conceptType=METRIC
        }
    }, 
    {
        dataType=STRING, 
        name=city_name, 
        label=City, 
        semantics=
        {
            conceptType=DIMENSION
        }
    }
], 
rows=
[
  {
    "values": [62, "Ancona"]
  },
  {
    "values": [326, "Bari"]
  },
  {
    "values": [78, "Bergamo"]
  },
  {
    "values": [396, "Bologna"]
  },
...
]
}