Webhooks của Meta cho quảng cáo tìm kiếm khách hàng tiềm năng để quản lý quan hệ khách hàng

Hướng dẫn này chỉ cho bạn cách triển khai quá trình tích hợp Webhooks của Meta cho quảng cáo tìm kiếm khách hàng tiềm năng để quản lý quan hệ khách hàng thông qua Webhooks.

Tổng quan

Một người dùng ứng dụng sẽ đăng nhập vào ứng dụng của bạn qua phương thức Đăng nhập bằng Facebook, đồng thời cấp cho ứng dụng đó những quyền cần thiết đối với Trang Facebook của họ mà đã đăng ký nhận Webhooks của Meta về khách hàng tiềm năng. Phương thức Đăng nhập bằng Facebook sẽ trả về một mã truy cập Trang có phạm vi quyền cần thiết để người dùng ứng dụng có thể xem thông báo về khách hàng tiềm năng mà Meta gửi đến máy chủ của bạn.

Trước khi bạn bắt đầu

Bạn sẽ cần:

Webhooks for Leads

Webhooks for Leads can send you real-time notifications of changes to your Page's Lead ads. For example, you can receive real-time updates whenever users click on a lead ad.

First, set up a Page Webhook:

  1. Set up your endpoint and configure the Webhooks product.
  2. Install your app using your Facebook page.

Setting Up Your Endpoint and Webhook Product

Follow our Getting Started guide to create your endpoint and configure the Webhooks product. During configuration, make sure to choose the Page object and subscribe to the leadgen field.

Install Your App

Webhook notifications will only be sent if your Page has installed your Webhooks configured-app, and if the Page has not disabled the App platform in its App Settings. To get your Page to install the app, have your app send a POST request to the Page's subscribed_apps edge using the Page's acccess token.

Requirements

  • A Page access token requested from a person who can perform the ADVERTISE task on the Page being queried
  • The following permissions:
    • leads_retrieval
    • pages_manage_metadata
    • pages_show_list
    • pages_read_engagement
    • ads_management

Sample Request

Formatted for clarity

curl -i -X POST "https://graph.facebook.com/{page-id}/subscribed_apps
  ?subscribed_fields=leadgen
  &access_token={page-access-token}"

Sample Response

{
  "success": "true"
}

To see which app's your Page has installed, send a GET request instead:

Sample Request

Formatted for clarity

curl -i -X GET "https://graph.facebook.com/{page-id}/subscribed_apps
  ?access_token={page-access-token}

Sample Response

{
  "data": [
    {
      "category": "Business",
      "link": "https://my-clever-domain-name.com/app",
      "name": "My Sample App",
      "id": "{page-id}"
    }
  ]
}

If your Page has not installed any apps, the API will return an empty data set.

Graph API Explorer

If you don't want to install your app programmatically, you can easily do it with the Graph API Explorer instead:

  1. Select your app in the Application dropdown menu. This will return your app's access token.
  2. Click the Get Token dropdown and select Get User Access Token, then choose the pages_manage_metadata permission. This will exchange your app token for a User access token with the pages_manage_metadata permission granted.
  3. Click Get Token again and select your Page. This will exchange your User access token for a Page access token.
  4. Change the operation method by clicking the GET dropdown menu and selecting POST.
  5. Replace the default me?fields=id,name query with the Page's id followed by /subscribed_apps?subscribed_fields=leadgen, then submit the query.

Common Uses

Getting Page LeadGen Details

Your app can subscribe to a Page's Leads and get notified anytime a change occurs. For example, here's a notification sent when a User clicked on a lead ad.

Sample Webhook Response

{
   "object": "page",
   "entry": [
       {
           "id": 153125381133,
           "time": 1438292065,
           "changes": [
               {
                   "field": "leadgen",
                   "value": {
                       "leadgen_id": 123123123123,
                       "page_id": 123123123,
                       "form_id": 12312312312,
                       "adgroup_id": 12312312312,
                       "ad_id": 12312312312,
                       "created_time": 1440120384
                   }
               },
               {
                   "field": "leadgen",
                   "value": {
                       "leadgen_id": 123123123124,
                       "page_id": 123123123,
                       "form_id": 12312312312,
                       "adgroup_id": 12312312312,
                       "ad_id": 12312312312,
                       "created_time": 1440120384
                   }
               }
           ]
       }
   ]
}

See Also

  • Visit our Lead Ads Retrieval guide to learn how to use the leadgen_id from the notification to retrieve data associated with the leads.