FB Development - how to search facebook cities for their "key"

Situation:

I am currently working on a project in which 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 submit a request to facebook, I get this response:

 { "data": [ { "name": "Sundsvall, Sweden", "key": 220260543, "subtext": "Vasternorrlands Lan, Sweden" }, { "name": "Sundsvallen, Sweden", "key": 220260542, "subtext": "Jamtlands Lan, Sweden" } ] } 

From this answer, I get the key and save it in my database table.

My problem

I also want to do the opposite and get a "name" and "subtext" by providing a "key". You know, "give me information where key = 220260543."

I know that I can store the name and subtext in my database, but I prefer to just keep the key.

Does anyone know if this is possible? How? Links? I read the facebook development doc but didn't find anything.

+6
source share
2 answers

If you don’t need a “subtext” / region, and you send the full names of cities (without using autocomplete in some context):

An alternative is to search for places (including cities) rather than adcities . This will give the graph identifier for the location, which can then be simply connected to the graph. Facebook.com

Request example:

 https://graph.facebook.com/search?q=sundsvall%20sweden&type=place&access_token=[TOKEN] 

This will give:

 { "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 just as well as Ladyland, you can drop it and everything else in the answer that does not match the “category”: “city”. Unfortunately, I’m not sure about the possibility to limit the results in cities ahead of time, but it seems that cities are consistently sorted high for this type of query, so the "query then filter" method should work.

Chart ID for Sundsvall, top result:

https://graph.facebook.com/110103992352737

+1
source

According to the documentation on Facebook, your request is used only to automatically fill in the ads API. The key is for the country only. There is nothing in their documentation that shows us how to go back from the key to the city. It seems that there is no FQL table for cities with a key column. And the schedule is still bare bones and even smaller.

0
source

Source: https://habr.com/ru/post/904950/


All Articles