How to configure Facebook webhooks?

Kamil Lelonek picture Kamil Lelonek · Dec 9, 2016 · Viewed 21k times · Source

I want to configure Facebook webhooks for the application I'm developing.

What I did so far was:

  1. Create FB app
  2. Go to app settings and create a new webhook:
    1. Add a valid callback URLs
    2. Choose particular fields
  3. Successfully save the settings

Now, when I'm querying for page subscriptions I get the response:

{
  "data": [
    {
      "object": "page",
      "callback_url": "CALLBACK_URL",
      "fields": [
        "feed"
      ],
      "active": true
    }
  ]
}

which seems to be valid.

What should I do next? How to start listening from feed of a particular page?

Answer

Kamil Lelonek picture Kamil Lelonek · Dec 12, 2016

Here is the entire configuration for Receiving API Updates in Real Time with Webhooks :

Step 1

  1. Create Facebook page
  2. Go to https://www.facebook.com/pg/YOUR_PAGE_NAME/about/?tab=page_info and read Facebook Page ID at the very bottom.

Step 2

  1. Create a developer account and a Facebook app
  2. Copy your Facebook App ID described in the above point.

Step 3

  1. Create a server application that will handle your Callback URL. A few examples are available on GitHub.
  2. Set up your Callback URL in the Facebook application you created in the previous step.

Step 4

Subscribe you Facebook App to your Facebook Page. To do that open Graph API Explorer.

  1. Obtain Page Access Token Alt text

Make sure you selected your particular application.

  1. After granting the permissions, select your particular page. The token will be put in Access Token field.
  2. Make POST request to the particular URL:

    /YOUR_PAGE_ID/subscribed_apps
    

Summary

That's it! With these steps you should have your server application up, running and listening on all events you declared!