I'm trying to implement the Facebook Realtime API with Meteor. I'm running in the following error - so something seems to be wrong with the callback url. It seems there is a html document returning, but I have no clue at which point this could happen:
[123.45.678.90] Exception while invoking method 'createSubscription' Error: error while subscribing to object page - failed [400] {"error":{"message":"(#2201) response does not match challenge, expected value = '1723842009', received='\u003C!DOCTYPE html>\n\u003Chtm...'","type":"OAuthException","code":2201}}
at subscription (packages/myname:realtime/lib/server/methods.js:37) at Meteor.methods.createSubscription (packages/myname:realtime/lib/server/methods.js:128) at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1594) at packages/ddp/livedata_server.js:648 at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56) at packages/ddp/livedata_server.js:647 at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56) at _.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646) at packages/ddp/livedata_server.js:546
More information about the Realtime API: https://developers.facebook.com/docs/graph-api/real-time-updates/v2.1
this is globally defined (iron route):
Router.map(function () {
this.route('fbCallbackURL', {
path: Meteor.settings.fbCallbackPath,
where: 'server',
action: function() {
var req = this.request;
var res = this.response;
switch(req.method){
case "GET" :
var hub = req.hub;
console.log("got something ...........");
if(hub && hub.verify_token === Meteor.settings.fbVerifyString
&& hub.mode==='subscribe' && hub.challenge){
res.writeHead(200, {"content-type": "application/json"});
res.end({hub: {challenge: hub.challenge}});
}
else{
res.writeHead(200, {"content-type": "application/json"});
res.end({message : "invalid request"});
}
break;
case "POST":
console.log("todo");
break;
default: console.log("other"); res.writeHead(404); res.end("");
}
}
})
});
serverside:
function subscription(object,fields,active){
if(object){
var url = 'https://graph.facebook.com/'+Meteor.settings.fbAppId+'/subscriptions'),
res,
params = {
access_token : Meteor.settings.fbAppId + '|' + Meteor.settings.fbAppSecret,
callback_url : Meteor.settings.fbAppURL+""+Meteor.settings.fbCallbackPath,
verify_token : Meteor.settings.fbVerifyString,
object : object,
fields : fields
};
try {
HTTP.post(url , { params: params } );
} catch (err) {
throw _.extend(
new Error("error while subscribing to object " + object + " - " + err.message + " ",{response: err.response}));
}
//return res;
}
else
new Error("subscription for invalid object requested!");
};
Meteor.methods({
createSubscription: function() {
return subscription("page","name",true);
}
});
on clientside I'm querying:
Meteor.call('createSubscription', function(err, data) {
if (err)
console.log(err);
else
console.log(data);
});