问题
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