facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
838 stars 518 forks source link

AdSet Creation Problem with the MOBILE_APP_INSTALLS Campaigns #96

Closed shanmukhark closed 9 years ago

shanmukhark commented 9 years ago

SDK version: 2.4

This flow works fine with Website Click Objective, however with the objective MOBILE_APP_INSTALLS fails. Please help me to locate the problem as error is not helping much to find the problem.

Regeneration Code:

        $adset = new AdSet(null, $account_id);
        $data = array(AdSetFields::NAME => 'LifetimeBudgetSet',
            AdSetFields::DAILY_BUDGET => intval($_REQUEST['fld_daily_budget']),
            AdSetFields::END_TIME => 0,
            AdSetFields::BID_AMOUNT => 500,
            AdSetFields::BILLING_EVENT => BillingEvents::APP_INSTALLS,
            AdSetFields::START_TIME =>
            (new \DateTime($_REQUEST['fld_start_date']))->format(DateTime::ISO8601),
            AdSetFields::END_TIME =>
            (new DateTime($_REQUEST['fld_end_date']))->format(DateTime::ISO8601),
            AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::APP_INSTALLS,
            AdSetFields::PROMOTED_OBJECT => array('application_id' => $app_info['application_id'], 'object_store_url' => $app_info['object_url'],),
            AdSetFields::TARGETING => array('geo_locations' => array('countries' => array('US',),), 
                'user_os' => array('iOS_ver_7.0_and_above'),
                'user_device' => array(
                    'iphone',
                    'ipad',
                    'ipod'
                ),
            ),
            AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_ACTIVE,
            AdSetFields::CAMPAIGN_GROUP_ID => $campaign_id);
        print_r($data);
        $adset->validate($data);

Error:

Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /home/ads_api/sdk/FacebookAds/Http/Exception/RequestException.php:137 Stack trace: #0 /home/ads_api/sdk/FacebookAds/Http/Client.php(216): FacebookAds\Http\Exception\RequestException::create(Array, 500) #1 /home/ads_api/sdk/FacebookAds/Http/Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /home/ads_api/sdk/FacebookAds/Api.php(152): FacebookAds\Http\Request->execute() #3 /home/ads_api/sdk/FacebookAds/Api.php(194): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 /home/ads_api/sdk/FacebookAds/Object/AbstractCrudObject.php(248): FacebookAds\Api->call('/act_1015278785...', 'POST', Array) #5 /home/ads_api/sdk/FacebookAds/Object/AbstractCrudOb in /home/ads_api/sdk/FacebookAds/Http/Exception/RequestException.php on line 137

Regards, Shanmukh

pruno commented 9 years ago

You should catch that exception, it will contain more info. Take a look at the exception methods here: https://github.com/facebook/facebook-php-ads-sdk/blob/master/src/FacebookAds/Http/Exception/RequestException.php#L160-L190

you should wrap your code into:

try { // your code here } catch (\FacebookAds\Http\Exception\RequestException $e) { echo $e->getErrorUserMessage(); // etc ... }

Closing this as u should find there what's wrong with your request. Feel free to re-open if necessary

shanmukhark commented 9 years ago

Thanks Pruno, I have chosen 'page_types' => array('mobilefeed') on TargetingSpecs to resolve it finally:-)