Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
3
Answers
Retrieve leads using weebhooks
Elouali Akram
4y
748
1
Reply
in the code below idk were my leads are stored ?
using
System;
using
System.Diagnostics;
using
System.Linq;
using
System.Net;
using
System.Net.Http;
using
System.Net.Http.Headers;
using
System.Threading.Tasks;
using
System.Web;
using
System.Web.Http;
using
FacebookLeadAdsWebhooks.Model;
using
Newtonsoft.Json;
namespace
FacebookLeadAdsWebhooks.Controller
{
public
class
WebhooksController : ApiController
{
#region Get Request
[HttpGet]
public
HttpResponseMessage Get()
{
var response =
new
HttpResponseMessage(HttpStatusCode.OK)
{
Content =
new
StringContent(HttpContext.Current.Request.QueryString[
"hub.challenge"
])
};
response.Content.Headers.ContentType =
new
MediaTypeHeaderValue(
"text/plain"
);
return
response;
}
#endregion Get Request
#region Post Request
[HttpPost]
public
async Task<HttpResponseMessage> Post([FromBody] JsonData data)
{
try
{
var entry = data.Entry.FirstOrDefault();
var change = entry?.Changes.FirstOrDefault();
if
(change ==
null
)
return
new
HttpResponseMessage(HttpStatusCode.BadRequest);
//Generate user access token here https://developers.facebook.com/tools/accesstoken/
const
string
token =
"<USER TOKEN>"
;
var leadUrl = $
"https://graph.facebook.com/v2.10/{change.Value.LeadGenId}?access_token={token}"
;
var formUrl = $
"https://graph.facebook.com/v2.10/{change.Value.FormId}?access_token={token}"
;
using
(var httpClientLead =
new
HttpClient())
{
var response = await httpClientLead.GetStringAsync(formUrl);
if
(!
string
.IsNullOrEmpty(response))
{
var jsonObjLead = JsonConvert.DeserializeObject<LeadFormData>(response);
//jsonObjLead.Name contains the lead ad name
//If response is valid get the field data
using
(var httpClientFields =
new
HttpClient())
{
var responseFields = await httpClientFields.GetStringAsync(leadUrl);
if
(!
string
.IsNullOrEmpty(responseFields))
{
var jsonObjFields = JsonConvert.DeserializeObject<LeadData>(responseFields);
//jsonObjFields.FieldData contains the field value
}
}
}
}
return
new
HttpResponseMessage(HttpStatusCode.OK);
}
catch
(Exception ex)
{
Trace.WriteLine($
"Error-->{ex.Message}"
);
Trace.WriteLine($
"StackTrace-->{ex.StackTrace}"
);
return
new
HttpResponseMessage(HttpStatusCode.BadGateway);
}
}
#endregion Post Request
}
}
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Variable value null.
How to Import/Download csv file in Jquery datatable