Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook "Boost Post" through API?

I've been crawling through the documentation and found out that it IS possible to achieve a "Boost Post" functionality through the Facebook Ad APIs. However, I have had some trouble finding what exactly the Boost Post does? i.e. Which part of the API corresponds the "Boost Post" functionality of the Facebook UI?

https://developers.facebook.com/docs/marketing-api/adcreative/v2.4

This page outlines several types of ads. What are the types Facebook "Boost Post" button makes? Or is this wrong part of the API?

like image 680
Muhwu Avatar asked Jul 13 '15 23:07

Muhwu


2 Answers

See the example for creating an ad_campaign here: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign#Creating

The object (page post in this case) you're trying to promote is set as the promoted object.

You can also set the lifetime or daily budget of the ad at the campaign level.

like image 144
Craig Kochis Avatar answered Sep 25 '22 12:09

Craig Kochis


From the Facebook docs,

For creating an ad from Page post ( boosting a post ), you will first need to create the creative for that ad from the post. See the doc page on how to create ad adcreatives. Search for Create an ad from an existing page post

use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');

$creative->setData(array(
  AdCreativeFields::NAME => 'Sample Promoted Post',
  AdCreativeFields::OBJECT_STORY_ID => <POST_ID>,
));

$creative->create();

After that you will need to create an ad using that creative ad. Creating ads from API with creative id

require __DIR__ . '/vendor/autoload.php';

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Ad;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;

$access_token = '<ACCESS_TOKEN>';
$app_secret = '<APP_SECRET>';
$app_id = '<APP_ID>';
$id = '<AD_ACCOUNT_ID>';

$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());

$fields = array(
);
$params = array(
  'name' => 'My Ad',
  'adset_id' => '<adSetID>',
  'creative' => array('creative_id' => '<adCreativeID>'),
  'status' => 'PAUSED',
);
echo json_encode((new AdAccount($id))->createAd(
  $fields,
  $params
)->exportAllData(), JSON_PRETTY_PRINT);

The examples on the above are using Facebook PHP Business SDK, but you can make the calls using the Facebook PHP Graph SDK with the same parameters. See the respective SDK files for finding the exact API parameters name. For example : the Business SDK parameter

AdCreativeFields::OBJECT_STORY_ID is object_story_id as the API parameter.

Hope that helps

like image 31
TheVigilant Avatar answered Sep 21 '22 12:09

TheVigilant