duandui5648 2018-08-08 11:28
浏览 114

如何使用facebook ads api创建图片广告

I am using Facebook ads api to manage Ads from my application and using fb PHP sdk 3.0 for this purpose. I am trying to create image ads and using following code for the same.

$account_id = "<MY_ACOUNT_ID>";
$ad_account = new AdAccount($account_id);
$photo_data = new AdCreativePhotoData();        
$photo_data->setData( array( AdCreativePhotoDataFields::URL => $data['url']) );
    $object_story_spec = new AdCreativeObjectStorySpec();
    $object_story_spec->setData(array(
        AdCreativeObjectStorySpecFields::PAGE_ID => <MY_PAGE_ID>,
        AdCreativeObjectStorySpecFields::PHOTO_DATA => $photo_data,
        'link'=>$data['link']
    ));

    $creative_params = array();
    $creative = new AdCreative(null, $account_id);  

        $creative_params['name'] = 'MY TEST ADS FROM API';      
        $creative_params['link_url'] = '<LINK URL OF IMAGE/WEBSITE>';   
        $creative_params['object_story_spec']  = $object_story_spec;        
    $creative->setData( $creative_params );     
    try{
        $creative->create();
        $fields = array();

        $params = array(
          'name' => 'MY TEST IMAGE ADS : VISH',
          'adset_id' => $data['adset_id'],
          'creative' => array('creative_id' => $creative->id),
          'status' => $data['status'],
        );                  

        try{
            $ads  = $ad_account->createAd($fields, $params);
            return $ads->id;
        } catch (Exception $e){             
             throw new Exception($e->getErrorUserTitle());
        } 
    } catch (Exception $e){         
         throw new Exception($e->getErrorUserTitle());
    }   

This generate ads in Facebook but when i see its preview in ads manager panel , it show this error.

Error screenshot Can anybody tell me , how to fix this issue.

  • 写回答

0条回答 默认 最新

    报告相同问题?