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 thanadcities
. This will yield a Graph ID for the location that can then just be plugged in to graph.facebook.com.Example query:
This will yield:
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