2

I created a facebook app. Then went to advanced settings and added an app page. Then went on created a webhook. It was successful. I selected page and subscribed to feed. Everything worked fine till here. But when I go to my page and post something on it Noting happens. I am not getting any request to my Server.

My Nodejs Code is this.

router.route('/v1/facebook/')
.get(function (req, res) {
    if (
        req.param('hub.mode') == 'subscribe' &&
        req.param('hub.verify_token') == 'FBToken'
    ) {
        res.send(req.param('hub.challenge'));
    } else {
        res.sendStatus(400);
    }
});

router.route('/v1/facebook/')
.post(function (req, res) {
    console.log('Facebook request body:');
    console.log(JSON.stringify(req.body))
    console.log('Facebook request body end:');
    // Process the Facebook updates here
    res.sendStatus(200);
});

When i click test it works

When I try this it show empty

Sunoj Vijayan
  • 138
  • 1
  • 12
  • Welcome to StackOverflow. Please edit your question to include more details - you haven't shown any code, or any other details that might help someone help you (aside from "it's not working"). – David Makogon Mar 02 '18 at 03:22
  • @DavidMakogon I have added the code. Thanks. – Sunoj Vijayan Mar 02 '18 at 03:41
  • Facebook will suspend the webhook, if your app does not respond with a 200 OK quickly enough multiple times. Remove your webhook, and add it again. – CBroe Mar 02 '18 at 07:28
  • I tried removing and adding the webhook again but no luck. I am sure I am doing something wrong. I just cannot pinpoint it. – Sunoj Vijayan Mar 02 '18 at 07:44
  • @CBroe I have added some images also. The first one when I click test it connects to my server and I am able to get the hook. But in second image I get empty response. – Sunoj Vijayan Mar 02 '18 at 07:49

1 Answers1

1

You need to make sure you have POSTed to me/subscribed_apps using a page access token generated by your application, this is what actually sets up the webhooks subscription for that specific page, allowing you to get callbacks.

Facebook call this 'installing' the app on the page. The documentation below is for the instagram API but the method is exactly the same as with the facebook API. https://developers.facebook.com/docs/instagram-api/webhooks#install-app

chrisc
  • 434
  • 3
  • 9