usman siddiqui
usman siddiqui

Reputation: 51

Invalid parameter while creating adset

While creating an Adset in facebook-ads-sdk i get invalid parameter. I tried my best to track and resolve the problem but couldn't succeed. Please help. Following is the code snippet:

   function adddSet($audienceid,$parentId,$accountId2,$campaignid,$productSetId){
    try {
        $adset = new AdSet(null, $accountId2);

        $adset->setData(array(
                AdSetFields::NAME => 'test',
                AdSetFields::DAILY_BUDGET =>40000,
                AdSetFields::BID_AMOUNT =>4000,
                AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
                AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::APP_INSTALLS,
                AdSetFields::CAMPAIGN_ID => $campaignid,                    
                AdSetFields::START_TIME => '2016-04-11T09:22:03+00:00',
                AdSetFields::END_TIME =>'2016-04-20T09:22:03+00:00',
                AdSetFields::TARGETING => (new TargetingSpecs())->setData(array(
                        TargetingSpecsFields::GEO_LOCATIONS => array(
                          'countries' => array('JP'),
                          'regions' => array(array('key' => '3886')),
                          'cities' => array(
                            array(
                              'key' => '2420605',
                              'radius' => 10,
                              'distance_unit' => 'mile',
                            ),
                          ),
                        ),
                        TargetingSpecsFields::GENDERS => array(1),
                        TargetingSpecsFields::AGE_MIN => 20,
                        TargetingSpecsFields::AGE_MAX => 24,
                        TargetingSpecsFields::PAGE_TYPES => array(
                          PageTypes::MOBILE_FEED,
                          PageTypes::MOBILE_EXTERNAL,
                        ),
                      )),
                  ));

        $adset->create(array(AdSet::STATUS_PARAM_NAME=>AdSet::STATUS_PAUSED));
    }
    catch(\FacebookAds\Http\Exception\RequestException $e){
        echo $e->getMessage();

    }
}

and get the following response:

Invalid parameter

Upvotes: 2

Views: 503

Answers (1)

Khurram Mazhar
Khurram Mazhar

Reputation: 21

This might help you to better understand exact error.

function adddSet($audienceid,$parentId,$accountId2,$campaignid,$productSetId){
    try {
        $adset = new AdSet(null, $accountId2);

        $adset->setData(array(
                AdSetFields::NAME => 'test',
                AdSetFields::DAILY_BUDGET =>40000,
                AdSetFields::BID_AMOUNT =>4000,
                AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
                AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::APP_INSTALLS,
                AdSetFields::CAMPAIGN_ID => $campaignid,                    
                AdSetFields::START_TIME => '2016-04-11T09:22:03+00:00',
                AdSetFields::END_TIME =>'2016-04-20T09:22:03+00:00',
                AdSetFields::TARGETING => (new TargetingSpecs())->setData(array(
                        TargetingSpecsFields::GEO_LOCATIONS => array(
                          'countries' => array('JP'),
                          'regions' => array(array('key' => '3886')),
                          'cities' => array(
                            array(
                              'key' => '2420605',
                              'radius' => 10,
                              'distance_unit' => 'mile',
                            ),
                          ),
                        ),
                        TargetingSpecsFields::GENDERS => array(1),
                        TargetingSpecsFields::AGE_MIN => 20,
                        TargetingSpecsFields::AGE_MAX => 24,
                        TargetingSpecsFields::PAGE_TYPES => array(
                          PageTypes::MOBILE_FEED,
                          PageTypes::MOBILE_EXTERNAL,
                        ),
                      )),
                  ));

        $adset->create(array(AdSet::STATUS_PARAM_NAME=>AdSet::STATUS_PAUSED));
    }
    catch(\FacebookAds\Http\Exception\AuthorizationException $e){
        print_r($e->getResponse()->getBody());

    }
}

Upvotes: 2

Related Questions