I’m trying to register new achievement on Facebook using RoR 3.2.8,
here is what my controller’s action looks like
require 'net/http'
require 'uri'
...
def create
# achievement url
@url = "http://smth.herokuapp.com/achievements/fb/ach.html"
# fb graph api url
@fbcall = "https://graph.facebook.com/#{FB_APP_ID}/achievements"
uri = URI(@fbcall)
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_PEER) do |http|
req = Net::HTTP::Post.new(uri.path)
req.set_form_data('access_token' => FB_APPLICATION_TOKEN, 'achievement' => @url, 'display_order' => '5')
response = http.request req
end
@ans = res.body.to_s()
end
I get the following @ans each time
{"error":{"message":"(#3502) Object at achievement URL is not of type game.achievement","type":"OAuthException","code":3502}}
However achievement html at @url has
<meta property="og:type" content="game.achievement" />
property in it.
If I put this html to Facebook debugger it does not show any errors and recognizes type as game.achievement.
If I write HTML form with inputs which makes auto-submit on load, the achievement is created OK.
So something seems to be wrong with the way I do post request from rails controller.
Any help, please %)
I noticed that if I put achievement
@urlto facebook debugger first, then it would register corresponding achievement.So now I do two ajax-requests: first one to facebook debugger and then (after the first is complete) to the facebook graph api.