Situation:
I'm currently working on a project where a user can search for a city. To get the result i use this url via ajax:
https://graph.facebook.com/search?q=**sundsvall**&type=adcity&country_list=**se**&access_token=
When I send a request to facebook like that I get a response like this:
{
"data": [
{
"name": "Sundsvall, Sweden",
"key": 220260543,
"subtext": "Vasternorrlands Lan, Sweden"
},
{
"name": "Sundsvallen, Sweden",
"key": 220260542,
"subtext": "Jamtlands Lan, Sweden"
}
]
}
From that response I get the key and store it in my database table.
My problem
I also want to to the opposite, and get the "name" & "subtext" by providing the "key". You know, "give me the information where key = 220260543".
I know i could store the name and subtext in my database to, but i prefer just to keep the key.
Anyone knows if this is possible? How? Links? I've read the facebook development doc's but haven't found anything yet.
If you don't need "subtext"/region, and you're sending full city names (not using in some autocomplete context):
An alternative is to search places
(which include cities) rather than adcities
. This will yield a Graph ID for the location that can then just be plugged in to graph.facebook.com.
Example query:
https://graph.facebook.com/search?q=sundsvall%20sweden&type=place&access_token=[TOKEN]
This will yield:
{
"data": [
{
"name": "Sundsvall, Sweden",
"category": "City",
"location": {
"latitude": 62.3833,
"longitude": 17.3
},
"id": "110103992352737"
},
{
"name": "Ladyland of Sweden",
"category": "Local business",
"location": {
"street": "Thulegatan 12",
"city": "Sundsvall",
"country": "Sweden",
"zip": "85232",
"latitude": 62.389481631972,
"longitude": 17.303409784226
},
"id": "170645612982568"
},
...
And as great as Ladyland sounds, you could discard it and anything else in the response not matching "category": "city". Sadly I'm not sure of a way to restrict the results to cities ahead of time, but it seems that cities are consistently sorted highly for this type of query, so the "query then filter" method should work.
Graph ID for Sundsvall, from above result:
https://graph.facebook.com/110103992352737
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With