6

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?

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90
  • 1
    Quote from the very page you linked to: _"page-related RTU objects will require that your app be installed on the page. [...] You can install the app for a Page using the /{page-id}/subscribed_apps edge."_ – CBroe Dec 09 '16 at 22:13
  • I am not getting any response after setup the call back. I just got custom token value and challange value while validating the callback. – Maneesh Rao Jan 19 '20 at 18:19

2 Answers2

20

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!

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90
  • Hi, thanks for your answer I tried however did not work well in my case, but the difference what I developed is the page was already published without messaging events. Do you think it changes something for webhook? – Yigit Alp Ciray Feb 11 '18 at 23:04
  • I'm not sure if I understand. – Kamil Lelonek Feb 12 '18 at 06:43
  • So, basically, all steps are done and when I trigger a webhook with test button it fires, however message conversations are still not triggering the server. What I am thinking is, is there any chance for that case the problem can be a difference between already published facebook page and not published page. – Yigit Alp Ciray Feb 12 '18 at 17:11
  • Is validation webhook going through? – Kamil Lelonek Feb 12 '18 at 20:19
  • I am not sure, how can I check that? – Yigit Alp Ciray Feb 13 '18 at 16:07
  • @kamil, yes my validation is perfectly getting response. But not getting page detail after adding subscribe. – Maneesh Rao Jan 19 '20 at 18:24
  • @YigitAlpCiray its exactly the same for me, its triggered by test button, but not with the real page evenets, did you find the reason for that? Any solution? Mybe it needs preview??? – Fahimeh Rahmatipoor Jul 18 '23 at 14:32
0

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.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Leo
  • 1
  • Not familiar with Python. Is this just putting the token in the body of a plaint/text response? The docs don't seem to specify in such detail. – Kenmore Feb 28 '18 at 21:45