Pergunta

I am doing the realtime update in node.js and I am not sure I have set the right endpointurl and the callback url which are '/facebookRealtime/callback' and domain+port+'/facebookRealtime/callback'. The error I am getting is "{"error":{"message":"(#2200) callback verification failed: Operation timed out after 6000 milliseconds with 0 bytes received","type":"OAuthException","code":2200}}", please tell me what happened and how to fix it.

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();
   };
Foi útil?

Solução

It looks like you are missing headers in your request with Content-Length and 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();
};

On top of this, you need to handle requests from Facebook with updates. If you do not handle them, then you will face errors.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top