Home > Blockchain >  How to pay for Facebook marketing campaigns via API to run ads created via FB's marketing API?
How to pay for Facebook marketing campaigns via API to run ads created via FB's marketing API?

Time:12-11

I am trying to create, manage and pay for Facebook marketing campaigns all via APIs. How can I set up the payment methods for those campaigns that I have created thru Facebook marketing API? Is there a popup dialog or an endpoint that can accept and/or store a payment method in facebook for these campaigns to bill the charges so that I can run the ads? I don't want to explicitly open any facebook's UI only to set up the payment methods. A popup dialog or a redirect would be fine.

Please guide me, I am lost in their documentations.

CodePudding user response:

I have figured out the solution. You need to include and use Facebook Javascript SDK and call the FB.ui() on an event. This function will take three properties and a callback.

<script>
function triggerPaymentDialog(){
  FB.ui({
      account_id: ‘<ACCOUNT-ID>’,
      display: 'popup',
      method: 'ads_payment',
      },
      function(response) {
       // use response 
       // if (response && !response.error_message).......
      }
    }
  );
}
</script>

It will open a popup on top of your app that will flow the user to either use any existing payment method on file with facebook or let the user add a new payment method to pay for campaigns.

Further details can be found here https://developers.facebook.com/docs/marketing-apis/guides/javascript-ads-dialog-for-payments/

  • Related