List of countries and cities to be used in Facebook Graph API for targeting

久未见 提交于 2019-12-01 05:43:41
Alan Albertengo

To check what countries are available you could just get a response from this endpoint:

URL: https://graph.facebook.com/API_VERSION/search?type=adgeolocation&location_types=['country']

HTTP_METHOD: GET

You also have to set your access token in the URL.

To just see the fields key and name and a larger quantity of countries without being paginated this would be the complete URL:

https://graph.facebook.com/API_VERSION/search?type=adgeolocation&location_types=['country']&fields=key,name&limit=1000

The file Facebook publishes seems valid for city/state/country lookups. It provides the graph id you will need. And it seems to parse as valid json for me.

Ok. I was able to use the same JSON file I mentioned in my question. As I said in my response to @offbysome, previously I had saved the file by opening it in Google Chrome. But then I used Firefox and used the Right Click => Save File As option to save the file on disk. This file is actually a tar gz (which facebook wrongly names as .php file). After unzipping the file, I was able to use the same code posted in my comment to get the PHP array which I then imported to MySQL.

For countries: search?type=adgeolocation&location_types=['countries']&limit=1000

For regions: search?type=adgeolocation&location_types=['region']&limit=1000&country_code=PT

Hope that helps :)

Well, for countries you could always check the Facebook Internationalization Document.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!