Skip to main content

Command Palette

Search for a command to run...

Retrieving Facebook lead ads using ASP.NET Web API and Graph API Web-hooks

Updated
2 min read
Retrieving Facebook lead ads using ASP.NET Web API and Graph API Web-hooks

ASP.NET way of retrieving Facebook Lead Ad data

Prerequisites

  • Facebook developer account
  • Visual Studio 2015 or higher

Web API Implementation

  • Create a standard ASP.Net MVC Web API solution, add a API Controller and name it as WebhooksController.cs finally copy the below code.

  • Compile and host the Web API in your server ( Note: SSL Certificate is mandatory. Facebook accept only HTTPS URL)

  • When an lead ad is generated Facebook will post the below data to the Web API’s Post action.

Sample data generated when a lead ad is generated

Facebook App & Web-hook Configuration

Creating new app

  • Provide the display name, contact email address and click Create App ID

Creating Facebook app id

  • Navigate to Add Product and setup Webhook

Add product

Setup Facebook webhook

  • Select Page from the pull-down menu and click Subscribe to this topic

Subscription

  • Provide the callback URL (Note: SSL is mandatory), Verification Token and click Verify and Save

Update subscription

  • On successful verification you will be prompted with a list of available subscriptions. From the list subscribe to Leadgen

Available subscriptions

Subscription confirmation

Testing

  • Click Test button in the leadgen subscription

Creating test

  • Facebook will open-up a popup with sample data, click Send to My Server button.

Test data

  • If there is any valid method like sending email, writing to database etc is implemented in the API post will get executed.

Complete source code can be downloaded here

[somaraj/Facebook-ASP.NET-Webhook
Facebook-ASP.NET-Webhook - Retrieving facebook leads using ASP.NET Web API and Graph API Webhooksgithub.com](https://github.com/somaraj/Facebook-ASP.NET-Webhook "https://github.com/somaraj/Facebook-ASP.NET-Webhook")