Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Geo-targeting parameters being ignored by Facebook when posting through Koala #221

samdec opened this Issue · 5 comments

3 participants


When using Koala to create feed posts Facebook ignores the provided geo-targeting parameters. When using the FB Graph API explorer with the same parameters the post appears properly geo-targeted.

Here's example code that will reproduce the issue:

require 'koala'

page_oauth_token = "your_oauth_token"

graph_client =

params = {
"message" => "Hello Toronto!",
"targeting" => {
"countries" => "CA",
"cities" => "296875"

fb_id = your_page_id

graph_client.put_object(fb_id, "feed", params)

The message appears on Facebook, but without any geo-targeting. You can use the Graph API explorer to pass in the same parameters (as JSON though) and use the same OAuth token to create a post that is geo-targeted.


I was able to resolve this by converting the targeting hash into JSON before posting through Koala.

Add these lines to the code and it works:

require 'yajl'

params["targeting"] = Yajl::Encoder.encode(params["targeting"])

We've actually run into a similar problem with adding custom actions (like a Share button) to FB page posts. We have to encode the actions parameter as JSON and put it inside an array.


I have found that the same is true as well


Sigh. I've seen this in several places, and I'm not sure there's anything we can do about this in Koala -- the API is deliberately ignorant of the details of the Facebook API, and there's no clear documentation of the geotargeting API that I can find, let alone all the places where Facebook requires you to JSON-encode parameters.

I would actually highly recommend filing a Facebook bug to ask that (a) this be properly documented and (b) they remove the requirement to JSON-encode the targetting string separately from the rest of the body (e.g. forcing us to double-encode it). I think that's all we can do. If you post the bug here I'd be happy to comment on it.

@arsduo arsduo closed this

We do this for custom share actions

  :actions => [{:name => 'Share', :link => share_url}].to_json

I forwarded this on to a friend at Facebook a whole back, who just told me he's filed an internal ticket (and acknowledged it's absurd). It looks like their system can't handle non-encoded nested params (this is also an issue with app restrictions).

I'm going to add a section in the Koala documentation for this -- let me know if you find any other examples.

@arsduo arsduo reopened this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.