Configure Facebook Webhook[WebSub protocol]
Facebook added a product called Webhooks for subscribe to the changes and receive updates in real time without calling the API.This blog is about how to configure the webhook product in Facebook and integrate it in the ASP.net Application.
Webhooks are basically works with the protocol named as WebSub , which contains three main components
- Publisher.
- Subscriber.
- Hub.
Configure the end point in Asp.net Web API
Create the asp.net application . Create get/post end points for Facebook like below:
Now we need to Configure Facebook.
Here,get end point will get called once you subscribe to the Facebook webhook with hub.challenge token.You should echo back with the same for verification purpose.Post is the end point you are exposing to get notified on updates.
You can get the complete code in the the Git.
Create WebHook
- Go to the Dashboard of your Facebook Application : https://developers.facebook.com/apps/
- Select the Webhooks products.
- New Subscription > Page .

- Callback Url : API url needs to give here.In our case its "api/webhooks". Note: You need to give http/https urls. "localhost" is not allowed in the app.You can use ngrok for exposing your port public.
- Verify Token : once you verify this you will get hit in the get end point we configured with hub.challenge in the query.We are returning back the same challenge in the end point.
- Once Subscription created, select names you're interested in and subscribe.
You can test the sample notification by clicking the "Test" button .On test you can able to see the model of the request that we have created in the application model named as "Feed" in the post request.
Enable Page subscribe to your app.
- Open the Graph API Explorer : https://developers.facebook.com/tools/explorer/
- On the top right Combo Box, select your Application
- Just below, in the Token ComboBox, select your Page.
- Select the verb POST for the request
- Enter the path : {your-page-id}/subscribed_apps
- Submit : you should get a success.
We are done with it! Now try adding new post to the page and check get notified.!
Happy coding !!!
Reference:
https://developers.facebook.com/docs/graph-api/webhooks/
https://www.w3.org/TR/websub/
Reference:
https://developers.facebook.com/docs/graph-api/webhooks/
https://www.w3.org/TR/websub/
Comments
Post a Comment