How to set the gender in Facebook Marketing API targetting spec?
I've tried setting the gender but i'm getting gender is not a valid target spec field error.
targeting_spec = {"geo_locations":
{
"location_types": ["recent"],
"custom_locations": [
{
"latitude": 14.5764,
"longitude": 121.0851,
"radius": 17
}
]
},
"age_min": 18,
"age_max": 35,
"gender": "male", // Setting gender, doesn't work
"flexible_spec": [
{
"interests": [
{"id": "6002998074973", "name": "BTS"}
]
},
{
"interests": [
{"id": "6005882720291", "name": "Data Science"}
]
}
]
}
Found it! It should be genders.
The values are:
gender: [0] # All
gender: [1] # Men
gender: [2] # Women
From https://developers.facebook.com/docs/marketing-api/buying-api/targeting/:
genders: array
1=male
2=female.
Defaults to all.
For example:
targeting: {
genders: [1]
...
Related
I have this payload that I need to send to a server
"members": [
{
"names": "ben",
"date-of-birth": "1978-01-01",
"gender": "Male",
"surname": "surname",
"role": "Partner",
"total-cut": "100.00"
}
],
Only thing is at times there are no members, and following this am not supposed to send the array at all, it should just be nothing at all, no members.
For clarification, this is an example only, think there is a members object, like the above, schools object, courses object, only at times some of this come up empty and consequently I should omit the empty object entirely.
For example, in the below, if there are no members,,
{
"members": [
{
"names": "ben",
"date-of-birth": "1978-01-01",
"gender": "Male",
"surname": "surname",
"role": "Partner",
"total-cut": "100.00"
}
],
"courses": [
{
"name": "ben",
"number": "32",
"teacher": "Russ",
"cut": "10.00"
}
],
}
how can i create a conditional that omits the members and leaves courses only
{
"courses": [
{
"name": "ben",
"number": "32",
"teacher": "Russ",
"cut": "10.00"
}
],
}
For context this is a post request
I don't know if this has been solved or not yet (I hope yes :P). But this is a practical approach for reference in case others do run into a similar issue.
Problem
Before, here is a problem rephrasing just to make sure we are on the same line. If you have members, add them to the map otherwise no. In both these conditions the map should look like this:
// With members
{
"members": [
{
"names": "member_name",
//...
}
],
"courses": [
{
"name": "course_name",
//...
}
],
}
// Without members
{
"courses": [
{
"name": "course_name",
//...
}
],
}
Solution
In my opinion, the best way to handle this is to declare an empty Map() and conditionally add entries to it as fellows:
Map<String, dynamic> buildMyMap(){
final buffer = <String, dynamic>{};
if(members.isNotEmpty){
// Option 1
buffer.addEntries(MapEntry("members", members));
// Option 2
buffer["members"] = members;
}else{
// (Optional) In case you want to delete pre-existing members
buffer.remove("members");
}
if(courses.isNotEmpty){
// Option 1
buffer.addEntries(MapEntry("courses", courses));
// Option 2
buffer["courses"] = courses;
}else{
// (Optional) in case you want to remove pre-existing courses!
buffer.remove('courses');
}
return buffer;
}
You should declare the parameter members to be optional in your API, then you have no need to send this parameter.
you can do the following
final List members = [];
final List courses = [];
final map = {
if (members.isNotEmpty)
'members': [
for (final member in members)
{
"names": "ben",
"date-of-birth": "1978-01-01",
"gender": "Male",
"surname": "surname",
"role": "Partner",
"total-cut": "100.00"
}
],
if (courses.isNotEmpty)
'courses': [
for (final course in courses)
{
"name": "ben",
"number": "32",
"teacher": "Russ",
"cut": "10.00"
}
]
};
you can use if statement inside a map or a list in flutter,
also, if you want to multiple fields if a condition is met
final map2 = {
if(true)...{
'name': 'name',
'age': '12'
} else ...{
'name': 'NO NAME',
'age': 'NO AGE'
}
};
so I'm really new to working with the Google Analytics API. I have managed to make the request work:
{
"dateRange": {
"startDate": "2021-01-08",
"endDate": "2021-05-05"
},
"activityTypes": [
"GOAL"
],
"user": {
"type": "CLIENT_ID",
"userId": "2147448080.1620199617"
},
"viewId": "1556XXX89"
}
such that I can get back a json format file like:
{
"sessions": [
{
"sessionId": "1620199614",
"deviceCategory": "mobile",
"platform": "Android",
"dataSource": "web",
"activities": [
{
"activityTime": "2021-05-05T07:53:08.366983Z",
"source": "(direct)",
"medium": "(none)",
"channelGrouping": "Direct",
"campaign": "(not set)",
"keyword": "(not set)",
"hostname": "somewebsite.com",
"landingPagePath": "/client/loginorcreate/login",
"activityType": "GOAL",
"customDimension": [
{
"index": 1
},
{
"index": 2
},
{
"index": 3,
"value": "59147"
}
],
"goals": {
"goals": [
{
"goalIndex": 1,
"goalCompletions": "1",
"goalCompletionLocation": "/order/registerorder/postregister.html",
"goalPreviousStep1": "page-z",
"goalPreviousStep2": "page-y",
"goalPreviousStep3": "page-x",
"goalName": "order"
}
]
}
}
],
"sessionDate": "2021-05-05"
}
],
"totalRows": 1,
"sampleRate": 1
}
now, ideally, I would get a different format response, and more importantly on where I don't have to specify each individual client ID. is there such a request format I can build, which would return something like:
clientID1 | activityTime | sessionId | activities
clientID2 | activityTime | sessionId | activities
clientID3 | activityTime | sessionId | activities
thanks!
The google analytics api returns data in the json format that you are seeing currently. How you format that data will be up to you this must however been done locally by you.
I am new in Dart and I have been trying to access the value of "farm_size" key in the following piece of code but unsuccessful. I can access up to "farms" like this
print(myData1[0]["farms"]);
But not any further. Any help will be appreciated. Thanks.
void main() {
var myData1 = [
{
"id": 1,
"first_name": "Jordan",
"sur_name": "Zamunda",
"member_n0": "AA1",
"gender": "male",
"phone": "123456789",
"email": "jordan#example.com",
"farms": [
{"id": 1, "farm_name": "SOUTH_FARM", "farm_size": "160 acres"},
{"id": 2, "farm_name": "NORTH_FARM", "farm_size": "190 acres"}
]
}
];
print(myData1[0]["farms"]);
}
inside farms, there is a list of more maps, to access those maps, you need to specify the index of the map you, for example we want to get the first map, we type:
print(myData1[0]["farms"][0]);
//this will print => {"id": 1, "farm_name": "SOUTH_FARM", "farm_size": "160 acres"}
//to get the name of this farm, you use the key 'farm_name' now:
print(myData1[0]["farms"][0]['farm_name']);
//prints=> SOUTH_FARM
If you're running it in dartpad, this will work:
void main() {
var myData1 = [
{
"id": 1,
"first_name": "Jordan",
"sur_name": "Zamunda",
"member_n0": "AA1",
"gender": "male",
"phone": "123456789",
"email": "jordan#example.com",
"farms": [
{"id": 1, "farm_name": "SOUTH_FARM", "farm_size": "160 acres"},
{"id": 2, "farm_name": "NORTH_FARM", "farm_size": "190 acres"}
]
}
];
List<Map<String,dynamic>> _list = myData1[0]["farms"]as List<Map<String,dynamic>> ;
print(_list[0]['farm_name']);
}
try this
List m = myData1[0]['farms'] as List;
print(m[0]['id']);
why is it that the riders have a null rider_id in the example? but the description says otherwise? riders[].rider_id : The hashed rider uuid. It doesnt say anything about it being may be null. Else what's the point of returning it. GET request
or is just an example, and the actual response has all of these ids not null
{
"product_id": "17cb78a7-b672-4d34-a288-a6c6e44d5315",
"request_id": "a1111c8c-c720-46c3-8534-2fcdd730040d",
"status": "accepted",
"surge_multiplier": 1.0,
"shared": true,
"driver": {
"phone_number": "(555)555-5555",
"sms_number": "(555)555-5555",
"rating": 5,
"picture_url": "https:\/\/d1w2poirtb3as9.cloudfront.net\/img.jpeg",
"name": "Bob"
},
"vehicle": {
"make": "Bugatti",
"model": "Veyron",
"license_plate": "I<3Uber",
"picture_url": "https:\/\/d1w2poirtb3as9.cloudfront.net\/car.jpeg"
},
"location": {
"latitude": 37.3382129093,
"longitude": -121.8863287568,
"bearing": 328
},
"pickup": {
"latitude": 37.3303463,
"longitude": -121.8890484,
"eta": 5
},
"destination": {
"latitude": 37.6213129,
"longitude": -122.3789554,
"eta": 19
},
"waypoints": [
{
"rider_id":null,
"latitude":37.77508531,
"type":"pickup",
"longitude":-122.3976683872
},
{
"rider_id":null,
"latitude":37.773133,
"type":"dropoff",
"longitude":-122.415069
},
{
"rider_id":"8KwsIO_YG6Y2jijSMf",
"latitude":37.7752423,
"type":"dropoff",
"longitude":-122.4175658
}
],
"riders": [
{
"rider_id":"8KwsIO_YG6Y2jijSMf",
"first_name":"Alec",
"me": true
},
{
"rider_id":null,
"first_name":"Kevin",
"me": false
}
]
}
The riders array, as specified in the GET /request/{request_id} reference page, is returned only for shared rides (uberPOOL rides). You will only be able to get a non-null rider_id if that rider account has already authenticated with your developer app.
This means that if any rider_id in the riders array is null, the rider account associated with that rider_id has not authenticated with your app.
I'm trying to post data to a mapquest table and I've done everything according to their API
Here is my json:
{
"tableName": "mqap.jZ3uoAVablablabla_reported_points",
"append": true,
"returnResults": true,
"rows": [
[
{
"mqap_geography": "POINT (-123.3141509 48.4647675)",
"date": "2016-03-13T02:19:09.674Z",
"email": "anna#gmail.com",
"latitude": "48.47542496514236",
"longitude": "-123.37663650512695",
"message": "ss",
"user": "a"
}
]
]
}
Here is a screenshot of the table
And this is the response I get in Postman
{
"failures": [
{
"reason": "Either no latitude/longitude was provided, or the other information was insufficient for geocoding at or near line #0 of input.",
"row": ""
}
],
"append": true,
"returnResults": true,
"totalRows": 1,
"tableName": "mqap.jblablabla_reported_points",
"tableSize": {
"raw": 8192,
"readable": "8 KB"
},
"data": {
"rows": []
},
"failureCount": 1,
"rowCount": 0,
"info": {
"statusCode": 0,
"copyright": {
"text": "© 2015 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "© 2015 MapQuest, Inc."
},
"messages": []
}
}
What am I doing wrong?
The geography column should be in the table by default when the table is created: mqap_geography. This column is populated depending on information in other columns depending on their data type: Geography, [Latitude, Longitude], [Street, City, StateProvince, PostalCode, County, Country], and FullAddress. The Latitude, Longitude columns in the table above are type String so they won't populate the Geography column.
Two things I was missing:
The database NEEDS to have a geography object. So I added a latlong Geography object that I didn't end up using.
The format of the JSON should've been the following:
{
"tableName": "mqap.jZ3uoAVablablabla_reported_points",
"append": true,
"returnResults": true,
"rows": [
[
{"name":"user","value":user},
{"name":"email","value":email},
{"name":"date","value":date},
{"name":"message","value":message},
{"name":"latitude","value":latitude},
{"name":"longitude","value"longitude},
{"name":"latlong","value":"POINT(" + parseFloat(longitude) + " " + parseFloat(latitude) +")"}
]
]
}