Kamil Lelonek
Kamil Lelonek

Reputation: 14764

How to configure Facebook webhooks?

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?

Upvotes: 6

Views: 26685

Answers (2)

Leo
Leo

Reputation: 1

For Django to respond to the VERIFY with a CHALLENGE back, here is a snippet to handle this in the view.py:

VERIFY_TOKEN = '******'

def fbwebhook(request):
    if request.GET['hub.verify_token'] == VERIFY_TOKEN:
        return HttpResponse(request.GET['hub.challenge'])
    else:
        return HttpResponse('Error, invalid token')

I referenced this GitHub repository.

Upvotes: 0

Kamil Lelonek
Kamil Lelonek

Reputation: 14764

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!

Upvotes: 20

Related Questions