How do I get a specific item from GetSchema in GetData/ Google Data Studio and Google Apps Scripts?

懵懂的女人 提交于 2019-12-11 16:03:43

问题


I need to get a specific field from the Get Schema, so I can do a conditional and set which URL to call as soon as the field is called in the Datastudio panel, I've followed some examples, but still haven't succeeded, would that be possible?

The codes are as follows

Geschema, array position element 22

var faceBookDataSchema = [
 {
      "name": "date_start",
      "label": "DATE",
      "description": "Date",
      "dataType": "STRING",
      "semantics": {
        "conceptType": "DIMENSION",
        "semanticType": "YEAR_MONTH_DAY"
      }
    },
]

function getSchema(request){ 
  var teste = {schema: faceBookDataSchema}; 
  return teste;
}; 
.......

GetData:
function getData(request){
 var fieldsDate = request.fields.forEach(function(field){
    for (var i = 0; i < faceBookDataSchema.length; i++){
      if(faceBookDataSchema[i].name === field.name){
        return faceBookDataSchema[i]['name'][22];
        break;
      }
    }
  });



 if(fieldsDate){
 var url= https://graph.facebook.com/v3.2/act_xxxxx/insights?fields=reach,frequency&level=Ad&time_range[since]=2019-02-11&time_range[until]=2019-03-11&time_increment=1;
  }else{
  var url = https://graph.facebook.com/v3.2/act_xxx/insights?fields=reach,frequency;
  }

 var response = UrlFetchApp.fetch(url,{
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + service.getAccessToken()
    }
  });
  var ApiMarketing = JSON.parse(response.getContentText());

来源:https://stackoverflow.com/questions/55168569/how-do-i-get-a-specific-item-from-getschema-in-getdata-google-data-studio-and-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!