Facebook marketing ap: cant create Ad - facebook

I receive an erro of Invalid parameter but it doesnt tell me which invalid parameter is. The error is:
Fatal error: Uncaught exception
'FacebookAds\Http\Exception\AuthorizationException' with message
'Invalid parameter' in
C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php:140
Stack trace: #0
C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Client.php(215):
FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response))
1 C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Request.php(282):
FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request))
2 C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(151):
FacebookAds\Http\Request->execute() #3
C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(193):
FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4
C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Object\AbstractCrudObject.php(208):
FacebookAds\Api->call('/act_XXXXXXXX...', 'POST', Array) #5 C:\A in
C:\AppServ\www\marketing\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php
on line 140
This is my code and it seems that the error is in the last object $ad = new Ad, everything is created fine until the Ad, it shows me this error.
<?php
//date_default_timezone_set('America/Lima');
//require_once('vendor/autoload.php');
//$campaign_id = '6053849657204';
// Configurations
$access_token = 'MYTOKEN';
$app_id = 'MYAPPID';
$app_secret = 'MYAPPSECRET';
$account_id = 'act_MYACCOUNT';
define('SDK_DIR', __DIR__ . ''); // Path to the SDK directory
$loader = include SDK_DIR.'/vendor/autoload.php';
date_default_timezone_set('America/Los_Angeles');
// Configurations - End
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');
}
use FacebookAds\Api;
Api::init($app_id, $app_secret, $access_token);
/**
* Step 1 Read the AdAccount (optional)
*/
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;
$account = (new AdAccount($account_id))->read(array(
AdAccountFields::ID,
AdAccountFields::NAME,
AdAccountFields::ACCOUNT_STATUS,
));
echo "\nUsing this account: ";
echo $account->id."\n";
// Check the account is active
if($account->{AdAccountFields::ACCOUNT_STATUS} !== 1) {
throw new \Exception(
'This account is not active');
}
/**
* Step 2 Create the Campaign
*/
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\AdObjectives;
$campaign = new Campaign(null, $account->id);
$campaign->setData(array(
CampaignFields::NAME => 'Noticia 1',
CampaignFields::OBJECTIVE => AdObjectives::LINK_CLICKS,
));
$campaign->validate()->create(array(
Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
echo "Campaign ID:" . $campaign->id . "\n";
/**
* Step 3 Search Targeting
*/
use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;
use FacebookAds\Object\TargetingSpecs;
use FacebookAds\Object\Fields\TargetingSpecsFields;
$results = TargetingSearch::search(
$type = TargetingSearchTypes::INTEREST,
$class = null,
$query = 'facebook');
// we'll take the top result for now
$target = (count($results)) ? $results->current() : null;
echo "Using target: ".$target->name."\n";
$targeting = new TargetingSpecs();
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
= array('countries' => array('PE'));
/*$targeting->{TargetingSpecsFields::INTERESTS} = array(
array(
'id' => $target->id,
'name' => $target->name,
),
);*/
/**
* Step 4 Create the AdSet
*/
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\OptimizationGoals;
use FacebookAds\Object\Values\BillingEvents;
$adset = new AdSet(null, $account->id);
$adset->setData(array(
AdSetFields::NAME => 'Latam 1',
AdSetFields::CAMPAIGN_ID => $campaign->id,
AdSetFields::DAILY_BUDGET => '150',
AdSetFields::TARGETING => $targeting,
AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH,
AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
AdSetFields::BID_AMOUNT => '1',
AdSetFields::START_TIME =>
(new \DateTime("+1 week"))->format(\DateTime::ISO8601),
AdSetFields::END_TIME =>
(new \DateTime("+2 week"))->format(\DateTime::ISO8601),
));
$adset->validate()->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
echo 'AdSet ID: '. $adset->id . "\n";
/**
* Step 5 Create an AdImage
*/
use FacebookAds\Object\AdImage;
use FacebookAds\Object\Fields\AdImageFields;
$image = new AdImage(null, $account->id);
$image->{AdImageFields::FILENAME}
= dirname(__FILE__).'/image.jpg';
$image->create();
echo 'Image Hash: '.$image->hash . "\n";
/**
* Step 6 Create an AdCreative
*/
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\Fields\AdCreativeFields;
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::MESSAGE => 'MY DESC',
AdCreativeLinkDataFields::LINK => 'MY WEB',
AdCreativeLinkDataFields::CAPTION => 'My caption',
AdCreativeLinkDataFields::IMAGE_HASH => $image->hash,
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => 'MY PAGE ID',
AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));
$creative = new AdCreative(null, $account->id);
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$creative->create();
echo 'Creative ID: '.$creative->id . "\n";
/**
* Step 7 Create an Ad
*/
use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;
$datax = array(
AdFields::NAME => 'My Ad',
AdFields::ADSET_ID => $adset->id,
AdFields::CREATIVE => array(
'creative_id' => $creative->id,
),
);
$ad = new Ad(null, $account->id);
$ad->setData($datax);
$ad->create(array(
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
echo 'Ad ID:' . $ad->id . "\n";

The issue was that you needed to specify a valid Link and Page ID. I figured that out by adding more logging in the code below by adding this piece of code,
use FacebookAds\Logger\CurlLogger;
Api::init($app_id, $app_secret, $access_token);
// Create the CurlLogger
$logger = new CurlLogger();
// To write to a file pass in a file handler
// $logger = new CurlLogger(fopen('test','w'));
// Attach the logger to the Api instance
Api::instance()->setLogger($logger);
Once you've added the above code to your php project, it will console output the curl version of the API calls being executed by the SDK. You can make the API call that was failing in a terminal using curl and get the specific error that the API throws for debugging. (Currently in the PHP SDK the exact error doesn't get propagated up in the exceptions.)
You can check out the complete working code snippet here,
<?php
$access_token = '<ACCESS_TOKEN>';
$app_id = <APP_ID>;
$app_secret = '<APP_SECRET>';
// should begin with "act_" (eg: $account_id = 'act_1234567890';)
$account_id = 'act_<ACCOUNT_ID>';
$page_id = 0; // REPLACE THIS WITH VALID PAGE ID.
// Configurations - End
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;
use FacebookAds\Logger\CurlLogger;
Api::init($app_id, $app_secret, $access_token);
// Create the CurlLogger
$logger = new CurlLogger();
// To write to a file pass in a file handler
// $logger = new CurlLogger(fopen('test','w'));
// Attach the logger to the Api instance
Api::instance()->setLogger($logger);
/**
* Step 1 Read the AdAccount (optional)
*/
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;
$account = (new AdAccount($account_id))->read(array(
AdAccountFields::ID,
AdAccountFields::NAME,
AdAccountFields::ACCOUNT_STATUS,
));
echo "\nUsing this account: ";
echo $account->id."\n";
// Check the account is active
if($account->{AdAccountFields::ACCOUNT_STATUS} !== 1) {
throw new \Exception(
'This account is not active');
}
/**
* Step 2 Create the Campaign
*/
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Values\AdObjectives;
$campaign = new Campaign(null, $account->id);
$campaign->setData(array(
CampaignFields::NAME => 'Noticia 1',
CampaignFields::OBJECTIVE => AdObjectives::LINK_CLICKS,
));
$campaign->validate()->create(array(
Campaign::STATUS_PARAM_NAME => Campaign::STATUS_PAUSED,
));
echo "Campaign ID:" . $campaign->id . "\n";
/**
* Step 3 Search Targeting
*/
use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;
use FacebookAds\Object\TargetingSpecs;
use FacebookAds\Object\Fields\TargetingSpecsFields;
$results = TargetingSearch::search(
$type = TargetingSearchTypes::INTEREST,
$class = null,
$query = 'facebook');
// we'll take the top result for now
$target = (count($results)) ? $results->current() : null;
echo "Using target: ".$target->name."\n";
$targeting = new TargetingSpecs();
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
= array('countries' => array('PE'));
/*$targeting->{TargetingSpecsFields::INTERESTS} = array(
array(
'id' => $target->id,
'name' => $target->name,
),
);*/
/**
* Step 4 Create the AdSet
*/
use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\OptimizationGoals;
use FacebookAds\Object\Values\BillingEvents;
$adset = new AdSet(null, $account->id);
$adset->setData(array(
AdSetFields::NAME => 'Latam 1',
AdSetFields::CAMPAIGN_ID => $campaign->id,
AdSetFields::DAILY_BUDGET => '150',
AdSetFields::TARGETING => $targeting,
AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH,
AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
AdSetFields::BID_AMOUNT => '1',
AdSetFields::START_TIME =>
(new \DateTime("+1 week"))->format(\DateTime::ISO8601),
AdSetFields::END_TIME =>
(new \DateTime("+2 week"))->format(\DateTime::ISO8601),
));
$adset->validate()->create(array(
AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
echo 'AdSet ID: '. $adset->id . "\n";
/**
* Step 5 Create an AdImage
*/
use FacebookAds\Object\AdImage;
use FacebookAds\Object\Fields\AdImageFields;
$image = new AdImage(null, $account->id);
$image->{AdImageFields::FILENAME}
= dirname(__FILE__).'/image.jpg';
$image->create();
echo 'Image Hash: '.$image->hash . "\n";
/**
* Step 6 Create an AdCreative
*/
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\Fields\AdCreativeFields;
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::MESSAGE => 'MY DESC',
AdCreativeLinkDataFields::LINK => 'www.google.com',
AdCreativeLinkDataFields::CAPTION => 'My caption',
AdCreativeLinkDataFields::IMAGE_HASH => $image->hash,
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => $page_id,
AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));
$creative = new AdCreative(null, $account->id);
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$creative->create();
echo 'Creative ID: '.$creative->id . "\n";
/**
* Step 7 Create an Ad
*/
use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;
$datax = array(
AdFields::NAME => 'My Ad',
AdFields::ADSET_ID => $adset->id,
AdFields::CREATIVE => array(
'creative_id' => $creative->id,
),
);
$ad = new Ad(null, $account->id);
$ad->setData($datax);
$ad->create(array(
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
echo 'Ad ID:' . $ad->id . "\n";

Related

How to load post ID using the gform_form_post_get_meta filter?

Trying to load post ID (and then some ACF field) of the post, where the form is currently embedded. Using get_the_id() or global $post w/ $post->ID returns NULL.
Loading post ID works correctly when using the other Gravity Forms filters (e.g. gform_admin_pre_render), but I was told using the gform_form_post_get_meta is the better way to do ths. What is the right approach for this?
add_filter( 'gform_form_post_get_meta' , 'my_populate_cpt_as_choices' );
function my_populate_cpt_as_choices( $form ) {
$current_post_id = get_the_id();
$postargs = array(
'post_type' => 'suhlasy',
'post_status' => 'publish',
'posts_per_page' => '-1',
);
$posts = get_posts( $postargs );
$input_id = 1; // this makes sure the checkbox labels and inputs correspond
foreach ( $posts as $post ) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if ( $input_id % 10 == 0 ) {
$input_id++;
}
$post_id = $post->ID;
$id_souhlasu = 1200 + $input_id;
$title = get_the_title($post_id);
$checkbox_text = get_field('checkbox_text', $post_id);
$text_suhlasu = get_field('text_suhlasu', $post_id);
$kategoria = get_field('kategoria_suhlas', $post_id);
// getting other fields for this post to display as values or checkbox labels
$nazev_souhlasu = GF_Fields::create( array(
'type' => 'consent',
'id' => $id_souhlasu, // The Field ID must be unique on the form
'formId' => $form['id'],
'isRequired' => true,
'label' => $title,
'parameterName' => 'my_custom_parameter',
'checkboxLabel' => $checkbox_text,
'description' => '<h2>' . $current_post_id . $post_id . $kategoria . '</h2><br>' . $text_suhlasu,
'pageNumber' => 1, // Ensure this is correct
) );
$form['fields'][] = $nazev_souhlasu;
$input_id++;
}
return $form;
}

Upload scorm packages in moodle course module using moodle rest api

I have already created a course using moodle RestAPI(function name : core_course_create_courses). then i want to upload a scorm package in moodle course module/activity.
i have write some code for that,this code will create a module in that course. i don't know how to upload scorm package in that course module.
here is my code
Add function core_course_create_modules in lib/db/services.php at line no : 327
'core_course_create_modules' => array(
'classname' => 'core_course_external',
'methodname' => 'create_modules',
'classpath' => 'course/externallib.php',
'description' => 'Creates modules in a course',
'type' => 'write',
'capabilities' => 'moodle/course:manageactivities',
)
Add 3 method in Courses/externallib.php file
2.1)create_modules_parameters
=> `public static function create_modules_parameters() {
$courseconfig = get_config('moodlecourse'); //needed for many default values
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'ID of the course'),
'modules' => new external_multiple_structure(
new external_single_structure(
array(
'modulename' => new external_value(PARAM_TEXT, 'Name of the module'),
'section' => new external_value(PARAM_INT, 'Sectionnumber'),
'name' => new external_value(PARAM_TEXT, "Title of the module", VALUE_OPTIONAL),
'visible' => new external_value(PARAM_INT, '1: available to student, 0:not available', VALUE_OPTIONAL),
'description' => new external_value(PARAM_TEXT, 'the new module description', VALUE_OPTIONAL),
'descriptionformat' => new external_format_value(PARAM_INT, 'description', VALUE_DEFAULT),
'groupmode' => new external_value(PARAM_INT, 'no group, separate, visible', VALUE_DEFAULT, $courseconfig->groupmode),
'groupmembersonly' => new external_value(PARAM_INT, '1: yes, 0: no', VALUE_DEFAULT, 0),
'groupingid' => new external_value(PARAM_INT, 'grouping id',VALUE_DEFAULT, 0)
)
)
)
)
);
}`
2.2) create_modules
`public static function create_modules($courseid, $modules) {
global $CFG, $DB;
require_once($CFG->dirroot . "/course/lib.php");
require_once($CFG->dirroot . "/course/modlib.php");
$moduleinfo = new stdClass();
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
// Clean the parameters.
$params = self::validate_parameters(self::create_modules_parameters(), array('courseid' => $courseid,'modules' => $modules));
$context = context_course::instance($course->id);
require_capability('moodle/course:manageactivities', $context);
foreach ($params['modules'] as $mod) {
$module = (object) $mod;
$moduleobject = $DB->get_record('modules', array('name'=>$module->modulename), '*', MUST_EXIST);
if(trim($module->modulename) == ''){
throw new invalid_parameter_exception('Invalid module name');
}
if (!course_allowed_module($course, $module->modulename)){
throw new invalid_parameter_exception('Module "'.$module->modulename.'" is disabled');
}
if(is_null($module->visible)){
$module->visible = 1;
}
if(is_null($module->description)){
$module->description = '';
}
if(!is_null($module->name) && trim($module->name) != ''){
$moduleinfo->name = $module->name;
}
$moduleinfo->modulename = $module->modulename;
$moduleinfo->visible = $module->visible;
$moduleinfo->course = $courseid;
$moduleinfo->section = $module->section;
$moduleinfo->introeditor = array('text' => $module->description, 'format' => $module->descriptionformat, 'itemid' => 0);
$moduleinfo->quizpassword = '';
$moduleinfo->groupmode = $module->groupmode;
$moduleinfo->groupmembersonly = $module->groupmembersonly;
$moduleinfo->groupingid = $module->groupingid;
$retVal = create_module($moduleinfo);
$result[] = array('id'=>$retVal->id);
}
return $result;
}`
2.3)create_modules_returns
`public static function create_modules_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'new module id')
)
)
);
}`
Parameters to call function
$module['courseid'] = 1; //course id
$module['modules'][] = array(
"section" => 2,//PARAM_INT, 'Sectionnumber'
"modulename" => "scorm",//PARAM_TEXT, 'Name of the module'
"name" => "Testing1",// OPTIONAL PARAM_TEXT, "Title of the module",
"visible" => 1,// OPTIONAL PARAM_INT, '1: available to student, 0:not available',
"description"=>"testing module using rest api", // OPTIONAL PARAM_TEXT, 'the new module description',
"descriptionformat"=>1,//PARAM_INT, 'description', VALUE_DEFAULT
//"groupmode" => "",//PARAM_INT, 'no group, separate, visible', VALUE_DEFAULT, $courseconfig->groupmode
//"groupmembersonly" => "",//PARAM_INT, '1: yes, 0: no', VALUE_DEFAULT, 0
//"groupingid" => "",//PARAM_INT, 'grouping id',VALUE_DEFAULT, 0
);
as per above code ,
its take name field as a scorm packages, in the admin side its display name as a scorm, when i was click on that its display errors:
screenshot for error
so, i don't know how to upload scorm package in course module using moodle Rest api, how can i do ?
Thank you.

Cant Create Facebook Ad via Ads API

I am trying to create a Facebook AD via their PHP SDK. The problem lies in the creation of the ad itself. If I comment out the last piece, its creates the adset. When I run this code, I get the error "a Parent ID is required"
try {
///////////////////////////// CREATE AD SET ////////////////////////////////////
$data = array(
AdSetFields::NAME => $adname,
AdSetFields::BID_TYPE => 'CPC',
AdSetFields::BID_INFO => array(
'CLICKS' => 6,
),
AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_PAUSED,
AdSetFields::DAILY_BUDGET => 500000,
AdSetFields::CAMPAIGN_GROUP_ID => $campaign_id,
AdSetFields::TARGETING => array(
'age_min' => 30,
'age_max' => 45,
'page_types' => array(
'desktopfeed',
),
'geo_locations' => array(
'countries' => array(
'US',
),
),
),
);
$adset = new AdSet(null, $account_id);
$adset->create($data);
$adset_id = $adset->id;
echo $adset_id.'-';
//////////////////////CREATE AD IMAGE ///////////////////////////////
$image = new AdImage(null, $account_id);
$image->{AdImageFields::FILENAME} = '../adimages/epsom.jpg';
$image->create();
$creative = new AdCreative(null, $account_id);
$creative->setData(array(
AdCreativeFields::TITLE => $adtitle,
AdCreativeFields::BODY => $addesc,
AdCreativeFields::OBJECT_URL => $tracking_promoted_url,
AdCreativeFields::IMAGE_HASH => $image->hash,
));
$creative->create();
echo $creative->id.'-';
/////////////////////////////// CREATE AD GROUP ////////////////////////////
$fields = array(array(
AdGroupFields::CREATIVE =>
array('creative_id' => $creative->id),
AdGroupFields::ADGROUP_STATUS => AdGroup::STATUS_PAUSED,
AdGroupFields::NAME => 'My First AdGroup',
AdGroupFields::CAMPAIGN_ID => $adset_id,
));
$ad = new AdGroup();
$ad->create($fields);
echo 'AdGroup ID:' . $adgroup->id . "-";
} catch (RequestException $e) {
echo 'Caught Exception: '.$e->getMessage().PHP_EOL
.'Code: '.$e->getCode().PHP_EOL
.'HTTP status Code: '.$e->getHttpStatusCode().PHP_EOL;
}
You're missing the parent ID parameter when you create the adgroup. The 2nd parameter should be the account ID you want to create this adgroup under:
$adgroup = new Adgroup(null, $accountId);
If you copied this from a doc, let me know and we can update.
You may reference to the latest doc: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign
From there, you will need to specify the ad account id(AD_ACCOUNT_ID) and ad campaign id(CAMPAIGN_GROUP_ID)

Facebook AdCreative->create() results in "Service temporarily unavailable"

My code:
// 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();
The exception:
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
If I change the access token or something the server responses the correct error. So I think the service is not really unavailable.

Send Email using cakephp 1.3

im using the code of this reference
http://books.google.com.ph/books?id=oXpiVSW5jqkC&pg=PT576&lpg=PT576&dq=app/views/elements/email/html&source=bl&ots=hAf3uDnVRb&sig=rrlbwekcKWfKhvmCvlYdFqC4EHQ&hl=en&sa=X&ei=dVnfUpbdB_GziQfSh4HgCA&ved=0CDAQ6AEwAQ#v=onepage&q=app%2Fviews%2Felements%2Femail%2Fhtml&f=false
i wrote the codes in my appcontroller in my emails_controller
<
lass EmailsController extends AppController {
public $components = array(
'Email' =>array(
'delivery' => 'smpt',
'smtpOptions' => array(
'host' =>
'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'redbaloons#gmail.com',
'password' => '123456789'
)
)
);
then after that i follow this to controllers index()
var $name = 'Emails';
function index() {
$this->Email->recursive = 0;
$this->set('emails', $this->paginate());
$this->Email->to = 'Destination<redbaloons#gmail.com>';
$this->Email->subject = 'Testing The Email component';
$sent('Hello World');
if(!$sent) {
echo 'ERROR: ' . $this->Email->smtpError . '<br />';
}else{
echo 'Email sent!';
}
then just test it, then i got this error
Fatal error: Function name must be a string in C:\xampp\htdocs\reservation\controllers\emails_controller.php on line 24
any configuration just to test this?? Please Help...
The syntax is wrong in this line:
$sent('Hello World');
I don't know exactly what you should be using, but it should be something like:
$sent = $this->Email->send("Hello World");