0

我正在 node.js 中进行实时更新,但我不确定我是否设置了正确的端点 URL 和回调 URL,它们是“/facebookRealtime/callback”和 domain+port+“/facebookRealtime/callback”。我得到的错误是“{“error”:{“message”:“(#2200)回调验证失败:操作在6000毫秒后超时,收到0字节”,“type”:“OAuthException”,“code”: 2200}}”,请告诉我发生了什么以及如何解决它。

exports.postSubscription=function (endpointUrl, appId, accessToken, object, fields,callback){

var options = {
        host:'graph.facebook.com',
        port:443,
        path:'/'+appId+'/subscriptions?access_token='+accessToken,
        method:'POST'
};
var postData = querystring.stringify({
    "object":object,
    "fields":fields,
    "callback_url": endpointUrl,
    "verify_token": "abc123"
});

var req = https.request(options, function(res){
    var data = "";
    res.on('data', function(chunk){
        data += chunk;
    });

    res.on('end', function(){
        callback(data);
        console.log(data);
    });

    res.on('error', function(e){
        callback(e.message, null);
    });
});
req.write(postData);
req.end();
   };
4

1 回答 1

0

看起来您的请求中缺少标头Content-Lengthand Content-Type

exports.postSubscription = function(endpointUrl, appId, accessToken, object, fields, callback) {
    var postData = querystring.stringify({
        "object": object,
        "fields": fields,
        "callback_url": endpointUrl,
        "verify_token": "abc123"
    });

    var options = {
        host:'graph.facebook.com',
        port:443,
        path:'/'+appId+'/subscriptions?access_token='+accessToken,
        method:'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': postData.length;
        }
    };

    var req = https.request(options, function(res) {
        var data = "";
        res.on('data', function(chunk) {
            data += chunk;
        });

        res.on('end', function() {
            callback(data);
            console.log(data);
        });

        res.on('error', function(e) {
            callback(e.message, null);
        });
    });
    req.write(postData);
    req.end();
};

最重要的是,您需要处理来自 Facebook 的更新请求。如果您不处理它们,那么您将面临错误。

于 2013-07-16T10:54:47.280 回答