FB Development - How to search facebook cities by their "key"

facebook places api
facebook places search api
facebook graph api search query
facebook search api
facebook places api pricing
facebook developer
facebook places database
facebook graph explorer


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:


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:


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:


charts - FB Development, 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� Hi guys, this video will show you the way to search people on Facebook by using the search filter tool. If you haven't used this tool on Facebook then you sh

According to Facebook's documentation your query is only used for doing auto-complete within the ads API. The key is only specific to a country as well. There is nothing in their documentation showing us devs how to go backwards from the key to the city. There appears to be no FQL table for cities that has a key column. And the graph is still bare bones and has even less.

Places Search - Places Graph, Either the q or center parameter must be included in your query. Sample request: curl -X GET "https://graph.facebook.com/search?type=place� Click a city's name. It should be below the search bar. This will refresh the search results to display people who have both the name and the city you selected on their profile. For example: if you typed in "Sarah Smith" as the name and selected New York as the city, you would see a list of people named Sarah Smith who live in New York

You can do so by requesting geometa data like this:

use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;

$result = TargetingSearch::search(
    'cities' => array(<city_key>),

If the returned array at key 'cities' is not empty, then you have a city matching that key:)

The doc to geometa data: https://developers.facebook.com/docs/marketing-api/audiences/reference/targeting-search/#geo-meta

Targeting Search - Marketing API, Cities. Since March 2019, we have reclassified several cities to other roles, but you can continue to use city . The search will return results� Probably not, since some people don’t have their age or city on their Facebook profile, while others may have incorrect or false data. (This is actually a good security measure - it’s generally unwise to put your real personal information on the i

Places Graph, With the Places Search API, you can search for millions of places worldwide, and To begin developing with the Places Graph SDK, get the Android or iOS SDK� Of course, Google followed suit with their own expansion in San Jose. You can call that a campus as much as you want, to me that sounds an awful lot like a city. “Don’t call it a city though”, Google and Facebook would say. It’s like Uber not wanting to be called a taxi and being regulated. Being called a city means the same. Regulation.

Facebook Places Graph API, Free access to data about more than 140M places around the world. Enable place discovery Enable search in Places Graph from Facebook for Developers � The Search box in the blue bar on top lets you search a lot of things on Facebook: pages, groups, events, even things your friends have liked. Most often, you use it to search for people. It may be people you’re already friends with and you just want to go to their Timelines.

Graph API Location, The Page Public Content Access feature is required to scrape the LocationNode data of public pages. Any city identified is also a city you can use for targeting ads. Use an array of IDs sourced from the placetopic search endpoint An arbitrary, alphanumeric, developer-defined ID for this location, usually used to link� Important: Combine the search keywords. As said above, you can combine these phrases together and add things like time, location, interests, likes, etc. to get more specific results.

  • I know this is already almost 5 years since this parent post, and I wanted to cry, when I saw what kind of output you can get there. Today we can get only object with two keys { "name": "Sundsvall, Sweden", "id": "110103992352737" }, and after this I have to make yet another call to get more information. YUCK! Why people did remove such an information away from this endpoint.
  • This uses the Business PHP SDK. In the docs it shows the way for curl as well.