Open samdec opened 12 years ago
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.
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.
Hey @arsduo, was there ever a solution to this? I am trying to geo target a wall post for a client's fb page and the targeting is still just ignored.
@ctres apologies for the late response. Was it being ignored even if you JSON-encoded it?
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 = Koala::Facebook::API.new(page_oauth_token)
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.