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

♀尐吖头ヾ 提交于 2019-11-30 04:51:15

问题


I am looking for a list of countries/states/cities that can be used with Facebook Graph API when publishing targeted posts.

I found one JSON file available on this page but the file doesn't parse correctly and I also doubt whether it can be used for post targeting since the file is for advertisements.

Also, I am not sure whether the third party data like the one provided by MaxMind can be used directly with Facebook API.

Does anyone have such a list or can atleast point me to a right direction?


回答1:


The answer is here: https://developers.facebook.com/docs/reference/ads-api/get-autocomplete-data/




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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 :)




回答6:


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



来源:https://stackoverflow.com/questions/7227498/list-of-countries-and-cities-to-be-used-in-facebook-graph-api-for-targeting

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