1

我正在尝试使用 Meteor 实现 Facebook 实时 API。我在以下错误中运行 - 所以回调 url 似乎有问题。似乎有一个 html 文档返回,但我不知道在什么时候会发生这种情况:

[123.45.678.90] 调用方法“createSubscription”时出现异常错误:订阅对象页面时出错 - 失败 [400] {"error":{"message":"(#2201) 响应与质询不匹配,预期值 = ' 1723842009',收到='\u003C!DOCTYPE html>\n\u003Chtm...'","type":"OAuthException","code":2201}}
在订阅 (packages/myname:realtime/lib/server/methods.js:37) 在 Meteor.methods.createSubscription (packages/myname:realtime/lib/server/methods.js:128) 在 maybeAuditArgumentChecks (packages/ddp/livedata_server .js:1594) 在 packages/ddp/livedata_server.js:648 在 _.extend.withValue (packages/meteor/dynamics_nodejs.js:56) 在 packages/ddp/livedata_server.js:647 在 _.extend.withValue (packages /meteor/dynamics_nodejs.js:56) 在 _.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646) 在 packages/ddp/livedata_server.js:546

有关实时 API 的更多信息: https ://developers.facebook.com/docs/graph-api/real-time-updates/v2.1

这是全局定义的(铁路线):

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("");
      }

    }
})
});

服务器端:

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);
}


});

在客户端我正在查询:

Meteor.call('createSubscription', function(err, data) {
if (err)
console.log(err);
else
console.log(data);
});
4

0 回答 0