Aditya
Aditya

Reputation: 396

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

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?

Upvotes: 7

Views: 15370

Answers (6)

Rafael Pereira
Rafael Pereira

Reputation: 109

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

Upvotes: 1

Alan Albertengo
Alan Albertengo

Reputation: 146

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

Upvotes: 6

Aditya
Aditya

Reputation: 396

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.

Upvotes: 0

bkaid
bkaid

Reputation: 52093

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.

Upvotes: 0

ifaour
ifaour

Reputation: 38135

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

Upvotes: 0

Related Questions