Failed to get Facebook listing ads sent to our signed endpoint.

I'm currently trying to get Facebook to send all potential customers, as they are registered in real time for a subscribed endpoint. Facebook mentions in its documentation that this is possible by setting up a real-time update from a new ad campaign.

https://developers.facebook.com/docs/marketing-api/guides/lead-ads/v2.5#setting-up-realtime-updates

However, after a few hours, trying to integrate this, I could not get it to work. Below is a process that I have followed so far to no avail.

Application setup

I created the Facebook application (423332064458136), which is currently tied to my personal account. This application works live, but does not work on any platform, as it does not require approval through a review (as I understand it).

I registered a callback for this application using the application id and application secret. This was achieved using the following curl request.

curl \ -F "object=page" \ -F "callback_url=https://leadr.co.uk/external/handle-fb.php" \ -F "fields=leadgen" \ -F "verify_token=abc123" \ -F "access_token=423332064458136|<APP_SECRET>" \ "https://graph.facebook.com/v2.5/423332064458136/subscriptions" 

I got a response {success: true} after registering. To confirm this, in place, using the application token from the GraphAPI explorer, I ran the request along the following path:

/ 423332064458136 / subscriptions

And got the answer:

 { "data": [ { "object": "page", "callback_url": "https://leadr.co.uk/external/handle-fb.php", "fields": [ "leadgen" ], "active": true } ], } 

In the place https://leadr.co.uk/external/handle-fb.php I respond with hub_challenge, if necessary, and additionally registers everything that is sent via php: // input to a text file.

Set up lead ad

I installed a lead ad on the VoucherSelector page ( https://www.facebook.com/permalink.php?story_fbid=1009785315719107&id=140148862682761 ) using the instructions from the Facebook documentation: https://developers.facebook.com/docs/marketing-api /guides/lead-ads/v2.5 .

This parameter is currently inactive, since we do not want to spend any expenses on it at this stage of testing. However, he realized that accounts can still be registered using this URL (see above).

Then we signed this page to our application using the page access token. Using the graphAPI explorer, I selected our application and then received the page access token for the voucher page. Then I ran the following request to subscribe to a page in our application.

 curl \ -F "access_token=<PAGE_ACCESS_TOKEN>" \ "https://graph.facebook.com/v2.5/140148862682761/subscribed_apps" 

I got the {success: true} response from this. By running a GET request on the same endpoint, I get the answer as follows:

 { "data": [ { "category": "Business", "link": "https://www.facebook.com/games/?app_id=423332064458136", "name": "leadR - Lead Ads Collection", "id": "423332064458136" }, { "category": "Utilities", "link": "https://www.facebook.com/games/?app_id=2373072738", "name": "Discussion Boards", "id": "2373072738" } ], } 

Confirmation that the page is subscribed to our application.

At any time when registration is registered in this lead announcement, our endpoint does NOT end up in any payload.

Additional notes

  • I am the administrator of the voucher selection page that keeps ads running.
  • When I try to download tooltips created from this ad (of which there are currently 8), I only get myself in the download file.
  • Any attempt to use the / subscriptions _sample endpoint to send a test packet to our endpoint fails with the following error (this means that we are limited only by the ability to test using real accounts):

    {"error": {"message": "(# 3) The application must be whitelisted", "type": "OAuthException", "code": 3, "fbtrace_id": "HH5gInxafKP"}}

The view was stuck on how to get out of here. Has anyone had any success in sending this ad to the endpoint of the subscription?

+5
source share
1 answer

I successfully received the current real-time Facebook advertising updates on our endpoint using the PHP method through which Facebook passes through video .

You will need three things if you have your files on a test server or in real time.

1 - Properly configured application for Facebook. If you look above, you seem to have the callback url and application configured correctly. Just make sure the application has the correct callback url and the fields for "leadgen" are in the webhook settings. We also had problems with the application, access to the listener if it was not in the https domain (se make sure you have a valid SSL certificate), and you also want to grant application domain permissions in any security service such as Cloud Flare or another firewall so it will not be blocked from hitting the listener.

2 - PHP listener on your callback. Here, as we have created for PHP, I do not see your code above, so I will post it here, it may be different:

 <?php $challenge = $_REQUEST['hub_challenge']; $verify_token = $_REQUEST['hub_verify_token']; if ($verify_token == 'abc123') {echo $challenge;} //you can output the below to your error log and tail -f it to see them //feed in live, once you see them hit your error log you know your //listener works, then you can change the below code to handle the //array and grab the leadgen ID for a further GET request of that real-time entry; $input = json_decode(file_get_contents('php://input'), true); error_log(print_r($input, true)); ?> 

3 - The page of your site in CRM for subscribing to pages. This is what we used below, it is very simple, but it works as a good starting point for more fully integrating applications into your CRM:

  <h2>Lead Gen Platform</h2> <script> window.fbAsyncInit = function() { FB.init({ appId : 'USEYOUROWNAPPID', xfbml : true, version : 'v2.5' }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); function subscribeApp(page_id, page_access_token) { console.log('Subscribed Page to FB Leads Live Update ' + page_id); FB.api('/' + page_id + '/subscribed_apps', 'post', {access_token: page_access_token}, function(response) {console.log('Successfully subscribed page', response); }); } function checkLoginState() { FB.getLoginStatus(function(response) { console.log('statusChangeCallback'); console.log(response); console.log('successfully logged in', response); }); FB.login(function(response) { if (response.status == 'connected') { // Logged into your app and Facebook. FB.api ('me/accounts', function(response) { console.log('successfully retrieved pages', response); var pages = response.data; var ul = document.getElementById('list'); for (i = 0, len = pages.length; i < len; i++) { var page = pages[i]; var li = document.createElement('li'); var a = document.createElement('a'); a.href = "#"; a.onclick = subscribeApp.bind(this, page.id, page.access_token); li.appendChild(a); a.innerHTML = page.name; ul.appendChild(li); } }); } else if (response.status == 'not_authorized') { // The person is logged into Facebook, but not your app. } else { // The person is not logged into Facebook, so we're not sure if // they are logged into this app or not. } }, {scope: 'public_profile,manage_pages'}); } </script> <fb:login-button scope="public_profile,manage_pages" onlogin="checkLoginState();"> </fb:login-button> <ul id="list"></ul> 

Using the above, we successfully conducted our Facebook commercials, which began to hit our listener at the callback URL and, thus, allow us to process data in real time. Hope this helps with your question!

+2
source

Source: https://habr.com/ru/post/1234997/


All Articles