pythonfacebookjsongeotargetting

Geo Targeting Posts in Facebook using Graph API


I’ve been trying to post geolocation-targeted status updates on a Page through the Graph API, so far with limited success.

Using the Facebook graph api, I’ve been successfully able to geo-target countries, but not cities or locales.

Trying any of these:

>>> graph.put_object("me", "feed", message="Targeted at Boston", targeting={"countries": 'US', 'cities': 'boston, ma'})                                                                                     
>>> graph.put_object("me", "feed", message="Targeted at Boston", targeting={"countries": 'US', 'cities': ['us, boston, ma']})
>>> graph.put_object("me", "feed", message="Targeted at Boston", targeting=[{'country': 'us', 'city': 'boston', 'region': 'ma'}])
>>> graph.put_object("me", "feed", message="Targeted at Seattle", targeting={"countries": 'US', 'cities': [{'name': 'seattle, wa'}]})
>>> graph.put_object("me", "feed", message="Targeted at Seattle", targeting={"countries": 'US', 'cities': [{'name': 'seattle, wa'}]})

results in either a public post, or a post with CUSTOM privacy, but not targeted to any specific location.

This:

>>> graph.put_object("me", "feed", message="Targeted at Seattle", targeting={"countries": 'US'})

works to selectively target only the United States.

I'm using the Facebook python-sdk for the requests.

I’ve been trying multiple ways to get the targeting to work, but it’s poorly documented and there isn’t much information available on the Facebook developer forums.

Has anyone been able to pass json used to geotarget multiple targets....like Boston, MA, Paris, France (in french), and then both at the same time?


Solution

  • The problem is that you need the city and locale keys, which you can find here: https://developers.facebook.com/docs/reference/ads-api/get-autocomplete-data/

    Yes, you can pass multiple cities.