Having trouble getting the real time updates from Facebook working using Koala gem...
https://github.com/arsduo/koala/wiki/Realtime-Updates
I have followed the guide in the wiki. I have set up a callback url with the following in my routes file:
match "facebook/subscription", :controller => :facebooks, :action => :subscribe, :as => 'subscribe', :via => [:get,:post]
Then when Facebook makes the get request I have tried both the following in my controller to 'meet the challenge' as required in their docs (https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests):
class FacebooksController < ApplicationController
def subscribe
verify_token = "VERIFY_TOKEN"
if params["hub.mode"] == "subscribe" && params["hub.verify_token"] == verify_token
params["hub.challenge"]
else
false
end
end
end
I have also tried (with the route amended to the right action):
class FacebooksController < ApplicationController
def realtime_request?(request)
((request.method == "GET" && params['hub.mode'].present?) ||
(request.method == "POST" && request.headers['X-Hub-Signature'].present?))
end
def subscription
if(realtime_request?(request))
case request.method
when "GET"
challenge = Koala::Facebook::RealtimeUpdates.meet_challenge(params,'SOME_TOKEN_HERE')
if(challenge)
render :text => challenge
else
render :text => 'Failed to authorize facebook challenge request'
end
when "POST"
p params['object']
render :text => 'Thanks for the update.'
end
end
end
end
The result every time is the following error on their dashboard when I try to subscribe:
The URL couldn't be validated. Response does not match challenge, expected value="2090763306", received="\u003C!DOCTYPE html>\n\u003Chtm..."
And the following when I try to run this in the console:
Console cmd:
@updates.subscribe("user", "feed", "https://www.bettrplay.com/facebook/subscription" , "YOUR_VERIFY_TOKEN")
Console response:
Koala::Facebook::ClientError: type: OAuthException, code: 2201, message: (#2201) response does not match challenge, expected value="773833772", received="\u003C!DOCTYPE html>\n\u003Ch...", x-fb-trace-id: GbtUB+FcLJS [HTTP 400]
I am unsure what the issue is as I can not see what is being returned to Facebook and i am still a little unsure of what I should be using as the VERIFY_TOKEN.
Any help appreciated.