我的代码:
// Set your access token here:
$access_token = "XXX";
$app_id = "XXX";
$app_secret = "XXX";
// should begin with "act_" (eg: $account_id = 'act_1234567890';)
$account_id = "XXX";
$page_id = "XXX";
if(is_null($access_token) || is_null($app_id) || is_null($app_secret)) {
throw new \Exception(
'You must set your access token, app id and app secret before executing'
);
}
if (is_null($account_id)) {
throw new \Exception(
'You must set your account id before executing');
}
define('SDK_DIR', __DIR__ . '/..'); // Path to the SDK directory
$loader = include SDK_DIR.'/vendor/autoload.php';
use FacebookAds\Api;
Api::init($app_id, $app_secret, $access_token);
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\ObjectStorySpec;
use FacebookAds\Object\Fields\ObjectStorySpecFields;
use FacebookAds\Object\ObjectStory\LinkData;
use FacebookAds\Object\Fields\ObjectStory\LinkDataFields;
use FacebookAds\Object\ObjectStory\AttachmentData;
use FacebookAds\Object\Fields\ObjectStory\AttachmentDataFields;
use FacebookAds\Object\AdGroup;
use FacebookAds\Object\Fields\AdGroupFields;
// Create a new AdCreative
$creative = new AdCreative(null, $account_id);
$creative->{AdCreativeFields::NAME} = 'Multi Product Ad Creative';
// Create a new ObjectStorySpec to create an unpublished post
$story = new ObjectStorySpec();
$story->{ObjectStorySpecFields::PAGE_ID} = $page_id;
// Create LinkData object representing data for a link page post
$link = new LinkData();
$link->{LinkDataFields::LINK} = 'http://www.example.com/products';
$link->{LinkDataFields::CAPTION} = 'WWW.EXAMPLE.COM';
// Create 3 products as this will be a multi-product ad
$product1 = (new AttachmentData())->setData(array(
AttachmentDataFields::LINK => 'http://www.example.com/p1',
AttachmentDataFields::IMAGE_HASH => '<AD_IMAGE_HASH_1>',
AttachmentDataFields::NAME => 'Product 1',
AttachmentDataFields::DESCRIPTION => '$4.99',
));
$product2 = (new AttachmentData())->setData(array(
AttachmentDataFields::LINK => 'http://www.example.com/p2',
AttachmentDataFields::IMAGE_HASH => '<AD_IMAGE_HASH_2>',
AttachmentDataFields::NAME => 'Product 2',
AttachmentDataFields::DESCRIPTION => '$10.99',
));
$product3 = (new AttachmentData())->setData(array(
AttachmentDataFields::LINK => 'http://www.example.com/p3',
AttachmentDataFields::IMAGE_HASH => '<AD_IMAGE_HASH_3>',
AttachmentDataFields::NAME => 'Product 3',
AttachmentDataFields::DESCRIPTION => '$29.99',
));
// Add the products into the child attachments
$link->{LinkDataFields::CHILD_ATTACHMENTS} = array(
$product1,
$product2,
$product3,
);
$story->{ObjectStorySpecFields::LINK_DATA} = $link;
$creative->{AdCreativeFields::OBJECT_STORY_SPEC} = $story;
$creative->create();
例外:
Fatal error: Uncaught exception 'FacebookAds\Http\Exception\ServerException' with message 'Service temporarily unavailable' in C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Http\Exception\RequestException.php:140 Stack trace: #0 C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Http\Client.php(216): FacebookAds\Http\Exception\RequestException::create(Array, 500) #1 C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Http\Request.php(276): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Api.php(140): FacebookAds\Http\Request->execute() #3 C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Api.php(182): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Object\AbstractCrudObject.php(248): FacebookAds\Api->call('/act_XXX/...', 'POST', Array) #5 C:\xampp\htdocs\fbtool\facebook- in C:\xampp\htdocs\fbtool\facebook-php-ads-sdk-master\src\FacebookAds\Http\Exception\RequestException.php on line 140
如果我更改访问令牌或服务器响应正确的错误。所以我觉得这项服务真的不可用。