How to get audience_size in Interest plus Country query - facebook

Hi i'm still new in Facebook-ads-api I know this is a noob question,
I want to get the audience_size for the Interest in a specific country.
on the API sample it can only generate the whole world audience_size of an Interest
use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;
$results = TargetingSearch::search(
TargetingSearchTypes::INTEREST,
null,
'soccer'
);
// Sample Response
{
"data":[
{
"name":"Association football (Soccer)",
"id":6003107902433,
"audience_size":593326800,
"path":[
"Sports and outdoors",
"Sports",
"Association football (Soccer)"
],
"description":null
},
...other results...
]
}

In order to get the estimated audience, you can use the Reach Estimate.
You can see the documentation here: https://developers.facebook.com/docs/marketing-api/reference/ad-account/reachestimate/
Just pass the targeting object (which include the interest and the country) and get the result.

Related

Omit response fields on Bing maps query

I'm looking for ways to reduce my bing maps query response size. For example - If I'm interested in the road distance between Seattle and LA, I'd query:
http://dev.virtualearth.net/REST/V1/Routes?wp.0=seattle&wp.1=losangeles&key=
(sorry, you'll have to use your own key)
... and that would give me something this (~1kB):
{
...
[
{
estimatedTotal: 1,
resources:
[
{
__type: "Route:http://schemas.microsoft.com/search/local/ws/rest/v1",
bbox:
[
34.053493,
-123.393781,
47.604151,
-118.242588
],
id: "v65,h-1259215200,i0,a0,cen-US,dAAAAAAAAAAA1,y0,s1,m1,o1,t4,w5D47BElTIPU1~ArgmUSjRxBABAADgAVva_j4A0~U2VhdHRsZSwgV0E1~~~,w9ecGAxFDffU1~ArgmUSgxwaIFAADgAQw_AT8A0~TG9zIEFuZ2VsZXMsIENB0~~~,k1",
distanceUnit: "Kilometer",
durationUnit: "Second",
routeLegs:
[],
travelDistance: 1827.815,
travelDuration: 58573,
travelDurationTraffic: 60478
}
]
}
],
...
This would look good, except expanding the routeLegs node gives me another ~23kB of data in the response - the full route - which I don't need. Anyone knows a way how to filter this out (either routeLegs or any of the underlying nodes?)
Thanks
You can now use the routeAttributes parameter documented here: https://msdn.microsoft.com/en-us/library/ff701717.aspx

REST, cross-references and performances, which compromise?

After reading this excellent thread REST Complex/Composite/Nested Resources about nested structures in REST responses, I still have a question. What's the best choice in terms of performance about the response ?
Let's take an example.
I have an Category object, which contains some Questions. Those Questions contains some Answers. All of these structures have meta-informations.
Now, when querying an url like GET http://<base_url>/categories/, should I include a description of the Categories only, include Question description ? Which one, full description or simplified one ?
In other terms, what's the best solution between those :
{
"results":[
{
'id':1,
'name':'category1',
'description':'foobar',
'questions':[
{
'id':1234,
'question':'My question',
'author' : 4235345,
'answers':[
{
'id':56786,
'user':456,
'votes':6,
'answer':'It's an answer !'
},
{
'id':3486,
'user':4564,
'votes':2,
'answer':'It's another answer !'
},
]
},
...
]
}
...
]
}
OR SOLUTION 2 :
{
"results":[
{
'id':1,
'name':'category1',
'description':'foobar',
'questions':[
{
'id':1234,
'url':'http://foobar/questions/1234'
'answers':[
{
'id':56786,
'url':'http://foobar/answers/56786'
},
{
'id':3486,
'url':'http://foobar/answers/3486'
},
]
},
...
]
}
...
]
}
OR SOLUTION 3 :
{
"results":[
{
'id':1,
'name':'category1',
'description':'foobar',
'questions':'http://foobar/categories/1/questions'
}
...
]
}
Or maybe another solution ?
Thanks !
That depends on what the application will do with the data. If it is only going to display a list of categories, then it is very inefficient to transfer all the data it ever needs at once, especially if the categories are many, which will decrease response time of user (absolute no no).
These scenarios depend heavily on application and usage of data.
One optimization that we can do is, we can create two requests,
GET http://<base_url>/categories
Which will return minimal data immediately and another request,
GET http://<base_url>/categories?all=true
Which will return all data.
Then the client app can make some clever optimizations like, when user requests for categories, request one is sent and it will immediately render the data. Then after getting the list of categories the user will be idle for some time looking and we can use this opportunity to request all data using request two.
However, as I said this will largely depend on the application.

How to get a Facebook user's current country?

The Facebook Graph API provides a user's current location in two formats: name and ID. ID can be something like 104022926303756. Name can be something like Palo Alto, California or Beijing, China. From these two fields, how do I extract the country? All American locations are in the form [City], [State] whereas all non-American locations are in the form [City], [Country]. Can I code something less hacky than:
$states = array(
'Alabama'
'Alaska',
'Arizona',
// ...
);
$country = 'USA';
if (!in_array($locationName, $states)) {
preg_match('#, ([a-z]+$)#i', $locationName, $match);
$country = $match[1];
}
How about using this: http://developers.facebook.com/tools/explorer/?method=GET&path=fql%3Fq%3DSELECT%20current_location%20FROM%20user%20WHERE%20uid%3Dme()
?
As you can see, using FQL on user table, the JSON you'll receive is something like:
{
"data": [
{
"current_location": {
"city": "Turin",
"state": "Piemonte",
"country": "Italy",
"zip": "",
"id": 115351801811432,
"name": "Turin, Italy"
}
}
]
}
There you have the field country, much more readable :-)
EDIT: The link is broken because brakets are missing at the end of query, anyway the FQL query is:
SELECT current_location FROM user WHERE uid=me()
"me()" can be any user ID.
If you want more information you could use the latitude and longitude from https://graph.facebook.com/104022926303756 and feed them into a reverse geocoder.
http://maps.googleapis.com/maps/api/geocode/json?latlng=37.4293,-122.138&sensor=false
The Google API gives a lot of information, but it can be quite useful.
The country code may be a better idenfifier than the country name for example.
There's also the possibility to select output language. Adding &lang=sv gives you "Kalifornien" as the name of the state instead of "California".
It comes inside the signed request when they hit your app. It comes even when they still didn't approve your app.

Post to facebook with multiple cities target

I'm trying to post something with target parameters, and i can do that but specifying only one city. Is there any way to pass two or more cities?
I'm trying this way:
parameters.targeting = new {
countries = "some country",
cities = new [] { new { key = "city value" }, new { key = "other city value" } },
locales = "locale code"
};
But no success! How can i do this?
This is very unclear, but I am guessing you are just not formatting your array of cities correctly. See more here: https://developers.facebook.com/docs/reference/ads-api/targeting-specs/
I believe you should be using "name" instead of "key" for the cities, but again I really don't have enough information to go off of.
Specify key, radius & distance_unit. For key, see Targeting Search,
Cities. radius is a distance around cities, from 10 to 50 miles or 17
to 80 kilometers. distance_unit is mile or kilometer. Limit: 250.
Example: 'cities': [{'key':'2430536', 'radius':12,
'distance_unit':'mile'}]
Source: https://developers.facebook.com/docs/marketing-api/buying-api/targeting#location

How to Separate the Profile Details

I try to read education details from face book using JSON in IPhone.
I read all education details from Face book successfully.
But i get the whole details. I want to separate the school, college {PG and UG}. But the node having same name like school. and also the data wil be read first one school, and then read one college, then again read one school and read one college like that. somebody fill one school more than one college. somebody wil fill more than one school and one college, somebody wont fill school or college. some id having same number of schools and college. some id having different number of schools and college. So how to I identify the schools and college details separately. Please if anybody having any idea please share with me.
MY Doubt is how to identify the schools, and college and then print schools and college separately...
My sample output as follows..
"education":
[
{
"school":
{
"id":110402725649312,
"name":"10th class"
},
"year":
{
"id":102356633142124,
"name":"2001"
}
},
{
"school":
{
"id":111983532181734,
"name":"Bsc Maths"
},
"year":
{
"id":146950445337693,
"name":"2006"
},
},
{
"school":
{
"id":115980035092981,
"name":"+2"
},
"year":
{
"id":114786038555902,
"name":"2003"
}
},
{
"school":
{
"id":130814456944277,
"name":"mca"
},
"year":
{
"id":115598488468394,
"name":"2010"
},
}
}]
Thanks to all...
I don't know how to retrieve a school ID from Facebook based on the id field you're getting there, but I'm sure there's a way to traverse their Social Graph structure to find it.
The advice I have for you is: Use the json-framework to convert that into a native NSArray containing NSDictionaries. Then walking that data becomes a ton easier.