4

I'm trying to geotarget wall posts to my fan page using the Facebook PHP SDK.

The following snippet successfully posts a message to my wall, but the geotargeting isn't taking.

I'm new to programming and I've done my best to follow the documentation here but it's pretty sparse -- I'm not confident that my syntax is correct.

Any help would be very much appreciated.

//compiling the geotargeting parameters
$geoTarget = "{'cities':'Richmond,VA','regions':'Virginia','countries':'US'}";

//my arguments
$args = array(
'access_token'  => $page_access_token,
'message'       => "this is my message",
'targeting' => $geoTarget
);

//posts the message
$facebook->api("/$page_id/feed","post",$args);
Kara
  • 6,115
  • 16
  • 50
  • 57
Duplosion
  • 255
  • 3
  • 10
  • If you're sure you're following the examples and it's not working it may be worth reporting this a bug in the platform [bug tracker](https://developers.facebook.com/bugs/) – Igy Oct 25 '11 at 19:06
  • 1
    I got it working by replacing the alpha city name with a numeric identifier. – Duplosion Oct 26 '11 at 15:56

2 Answers2

2

To make this easier this is the bit you need http://developers.facebook.com/docs/reference/api/page/#targeting

this will give the info on how to target regions too. http://developers.facebook.com/docs/reference/ads-api/get-autocomplete-data/

What you need to complete the targeting in the question would be:

The countries bit was right. Virginia's region code is 51 (which you can find by searching _">https://graph.facebook.com/search?q=vi&type=adregion&match_country_code=true&country_list=US&access_token=_) Richmond's city id is 2538983 (which you can find by searching _">https://graph.facebook.com/search?q=richmon&type=adcity&limit=150&access_token=_)

so the geotarget would be

$geoTarget = "{'cities':[2538983],'regions':[51],'countries':'US'}";
  • Have you actually tried this and how did you verify that it works? I have not seen this work via the api and from the doc page you cite, you should also be able to read back the targeting by a GET of the post with fields=targeting but that gives an Oauth 100 error despite the access_token having manage_pages privs. From the UI it does not show the post being targeted (it shows Public) whereas posts targeted through the UI show Feed Targeted to: on hover. – tribalvibes Nov 13 '12 at 09:37
2

The field is privacy in the Post table

The description field may contain a comma-separated lists of valid country, city and language if a Page's post targeting by location/language is specified.

http://developers.facebook.com/docs/reference/api/post/

  • The documentation says to use `feed_targeting` parameter. Is that an error? or is it just the new field to use... So confusing! cf. http://developers.facebook.com/docs/reference/api/page/#targeting – maxwell2022 Jul 29 '13 at 01:47