facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.18k stars 1.96k forks source link

Throwing error for creating createAd #1033

Open nileshsmartwebtech opened 6 years ago

nileshsmartwebtech commented 6 years ago

`<?php /**

use FacebookAds\Object\AdAccount; use FacebookAds\Object\Campaign; use FacebookAds\Object\AdSet; use FacebookAds\Object\AdCreative; use FacebookAds\Object\Ad; use FacebookAds\Object\AdPreview; use FacebookAds\Api; //use FacebookAds\Logger\CurlLogger; //try{ $access_token = ''; $ad_account_id = 'act_105478390317505'; $account_id='105478390317505'; $app_secret = 'b2fbcb713f179935d5b4bcfa8c407982'; $page_id = '701194529963043'; $app_id = '2217624105131813';

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

$fields = array( ); $params = array( 'objective' => 'PAGE_LIKES', 'status' => 'PAUSED', 'buying_type' => 'AUCTION', 'name' => 'My Campaign', ); $campaign = (new AdAccount($ad_account_id))->createCampaign( $fields, $params ); $campaign_id = $campaign->id; echo '
campaign_id: ' . $campaign_id . "\n\n";

$fields = array( );

$params = array( 'status' => 'PAUSED', 'targeting' => array('geo_locations' => array('countries' => array('US'))), 'daily_budget' => '4000', 'billing_event' => 'IMPRESSIONS', 'bid_amount' => '20', 'campaign_id' => $campaign_id, 'optimization_goal' => 'PAGE_LIKES', 'promoted_object' => array('page_id' => $page_id), 'name' => 'My AdSet1', ); $ad_set = (new AdAccount($ad_account_id))->createAdSet( $fields, $params ); $ad_set_id = $ad_set->id; echo '
ad_set_id: ' . $ad_set_id . "\n\n";

$fields = array( ); $params = array( 'body' => 'Like My Page', 'image_url' => 'http://web-scraping.co.uk/trainer_app/assets/images/ic_logo_trim.png', 'name' => 'My Creative', 'object_id' => $page_id, 'title' => 'My Page Like Ad', ); $creative = (new AdAccount($ad_account_id))->createAdCreative( $fields, $params ); $creative_id = $creative->id; echo '
creative_id: ' . $creative_id . "\n\n";

$fields = array( ); $params = array( 'status' => 'PAUSED', 'adset_id' => $ad_set_id, 'name' => 'My Page Like Ad', 'creative' => array('creative_id' => $creative_id), ); $ad = (new AdAccount($ad_account_id))->createAd( $fields, $params ); $ad_id = $ad->id; echo '
ad_id: ' . $ad_id . "\n\n";

$fields = array( ); $params = array( 'ad_format' => 'DESKTOP_FEED_STANDARD', ); echo json_encode((new Ad($ad_id))->getPreviews( $fields, $params )->getResponse()->getContent(), JSON_PRETTY_PRINT);

/ }catch(Exception $e) { echo $e->getMessage(); print_r($e); }/ ?>`