8

मैंने जीयूआई का उपयोग करके फेसबुक विज्ञापनों और सामानों के बारे में बहुत कुछ पढ़ा है, जो मैं कर रहा हूं और एसडीके पर किसी कारण से ऐसा करने की अनुमति देता है।फेसबुक विज्ञापन एसडीके एपीआई के माध्यम से विज्ञापन पोस्ट करने की अनुमति नहीं देता है। उपकोड: 1487930

मुझे फेसबुक विज्ञापन एसडीके सबकोड पर यह सब आतंक कोड मिलता है।

संदेश का कहना है:

आप को बढ़ावा देने के लिए एक वस्तु का चयन करना होगा, उपयोगकर्ता संदेश का कहना है: आपका अभियान> अपने उद्देश्य>> (पूर्व से संबंधित बढ़ावा देने के लिए एक विज्ञापन एक चयनित ऑब्जेक्ट के साथ सेट शामिल करना चाहिए: पेज, यूआरएल, घटना)। जारी रखने के लिए कृपया अपना विज्ञापन सेट अपडेट करें।

प्रतिक्रिया में बिना क्षेत्रों रिटर्न दोष और त्रुटि होता है जब रचनात्मक बनाया जा रहा है: $creative->create();

मैं सेटअप इस तरह मेरी adset:

use Facebook; 
    use FacebookAds\Api; 
    use FacebookAds\Object; 
    use Facebook\Exceptions; 

     $inventory = new Models\AdvertisingInventory(); 
     $item = $inventory->getListing($id)->getAttributes(); 
     $item['properties'] = json_decode($item['properties'], true); 

     /** 
     * Step 1 Instantiate an API 
     * 
     * @link https://developers.facebook.com/docs/marketing-api/sdks#init-sdk 
     */ 

     try { 
      Api::init($this->app_id, $this->app_secret, $this->access_token); 
     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 
     } 

     /** 
     * Step 2 Query to create campaign 
     * @var $campaign 
     * @link https://developers.facebook.com/docs/marketing-api/reference/ad-campaign-group 
     * 
     * TODO: Implement ad image widget sizing: https://www.facebook.com/business/help/103816146375741 
     */ 
     try { 

      $account = new Object\AdAccount($this->current_facebook_ads_account); 

      $campaign = new Object\Campaign(null, $this->current_facebook_ads_account); // Getting AdAccount instance 

      $ad_campaigns = $account->getCampaigns($campaign::getFields())->getArrayCopy(); // Checks of there are any campaigns already created 

      $current_campaign = null; 

      if (!empty($ad_campaigns)) { 
       foreach ($ad_campaigns as $ad_campaign) { // loops through campaigns 
        $campaign_data = $ad_campaign->exportAllData(); 
        if ($campaign_data['name'] == 'Sell old inventory') { // If campaign name matches the name given to new campaign, created campaign is then used 
         $current_campaign = $ad_campaign; 
        } 
       } 
      } 

      if (!is_null($current_campaign)) { // Checks if campaign is already assigned if yes, then its used. 
       $campaign = $current_campaign; 
      } else { // else new one is created 
       $campaign->setData(array(
        Object\Fields\CampaignFields::NAME => 'Sell old inventory', 
        Object\Fields\CampaignFields::OBJECTIVE => Object\Values\CampaignObjectiveValues::LINK_CLICKS, 
       )); 

       $campaign->validate()->create(array(
        Object\Campaign::STATUS_PARAM_NAME => Object\Campaign::STATUS_PAUSED 
       )); 
      } 

      //$campaignData = $campaign->getData(); 

      echo 'Campaign ID: ' . $campaign->id . " <br>\n"; 

     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 
     } 

     /** 
     * Step 3 Search for targeting topic 
     * @var $targeting 
     * @link https://developers.facebook.com/docs/marketing-api/targeting-specs/v2.7 
     */ 
     try { 
      $results = Object\TargetingSearch::search(
       Object\Search\TargetingSearchTypes::INTEREST, 
       null, 
       'Automobiles'); 

      $target = (count($results)) ? $results->current() : null; 

      //if (!is_null($target)) { 

      echo "Using target: " . $target->name . "<br/>"; 

      $targeting = new Object\Targeting(); 
      $targeting->{Object\Fields\TargetingFields::GEO_LOCATIONS} = array(
       'countries' => array('NZ') 
      ); 
      $targeting->{Object\Fields\TargetingFields::INTERESTS} = array(
       array(
        'id' => $target->id, 
        'name' => $target->name, 
       ), 
      ); 
      //} 
     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 
     } 

     /** 
     * Step 4 Create an AdSet 
     * @var $adset 
     * @link https://developers.facebook.com/docs/marketing-api/reference/ad-campaign 
     */ 
     try { 

      $adset = new Object\AdSet(null, $this->current_facebook_ads_account); 
      //$fields = $adset::getFields(); 

      $available_adsets = $campaign->getAdSets(array(Object\Fields\AdSetFields::NAME,Object\Fields\AdSetFields::ID)); 

      $current_adset = null; 

      if (!empty($available_adsets)) { 
       foreach ($available_adsets as $ad_set) { // loops through adsets 
        if ($adset->name == $item['title']) { // If adset name matches the name given to new campaign, created campaign is then used 
         $current_adset = $ad_set; 
        } 
       } 
      } 

      if (!is_null($current_adset)) { 
       $adset = $current_adset; 
       /*$adset->read(array(
        Object\Fields\AdSetFields::PROMOTED_OBJECT, 
        Object\Fields\AdSetFields::NAME 
       )); 
       echo $adset->name."<br>"; 
       echo $adset->promoted_object."<br>";*/ 
      } else { 

       $start_time = (new \DateTime("+1 week"))->format(\DateTime::ISO8601); 
       $end_time = (new \DateTime("+2 week"))->format(\DateTime::ISO8601); 


       $adset->setData(array(
        Object\Fields\AdSetFields::NAME => $item['title'], 
        Object\Fields\AdSetFields::OPTIMIZATION_GOAL => Object\Values\AdSetOptimizationGoalValues::LINK_CLICKS, 
        Object\Fields\AdSetFields::BILLING_EVENT => Object\Values\AdSetBillingEventValues::LINK_CLICKS, 
        Object\Fields\AdSetFields::BID_AMOUNT => 100, 
        Object\Fields\AdSetFields::DAILY_BUDGET => 500, 
        Object\Fields\AdSetFields::CAMPAIGN_ID => $campaign->id, 
        Object\Fields\AdSetFields::TARGETING => $targeting, 
        Object\Fields\AdSetFields::START_TIME => $start_time, 
        Object\Fields\AdSetFields::END_TIME => $end_time, 
        Object\Fields\AdSetFields::PROMOTED_OBJECT => (object) array(
         Object\Fields\AdPromotedObjectFields::PAGE_ID => '178698438995498', 
        ) 
       )); 
       $adset->create(array(
        Object\AdSet::STATUS_PARAM_NAME => Object\AdSet::STATUS_PAUSED, 
       )); 
      } 
      echo 'Adset ID: ' . $adset->id . " <br>\n"; 
     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 
     } 


     //New method 
     /** 
     * Step 5 Create an AdImage 
     * @var $image 
     * @link https://developers.facebook.com/docs/marketing-api/reference/ad-image 
     */ 
     try { 
      $image = new Object\AdImage(null, $this->current_facebook_ads_account); // Invokes images preparation for Facebook ad instance 
      $target_path = __DIR__ . '/assets/temp/'; // path where images will be streamed to 

      if (!file_exists($target_path)) { 
       mkdir($target_path, 0755); // creating path if one doesn't exist 
      } 

      $files_in_dir = array_diff(scandir($target_path), array('..', '.')); // checking for existing files in target directory 
      $size = getimagesize($item['properties']['images_large'][0]); // getting image details 
      $extension = image_type_to_extension($size[2]); // getting image extension from type 
      $target_file_name = preg_replace(['/\./', '/\\s/', '/\\t/'], "_", strtolower($item['title'])) . $extension; // creating proper file name 
      $target_file = $target_path . $target_file_name; // setting full target directory 

      if (array_search($target_file_name, $files_in_dir) === false) { // checking if target file already exists 

       $image_file = file_get_contents($item['properties']['images_large'][0]); 

       file_put_contents($target_file, $image_file); 
      } 

      $image->{Object\Fields\AdImageFields::FILENAME} = $target_file; // Using target file as ad image 

      $image->create(); 

      echo 'Image Hash: ' . $image->hash . " <br>\n"; 
     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 
     } 

     /** 
     * Step 6 Create an AdCreative 
     */ 
     try { 

      $creative = new Object\AdCreative(null, $this->current_facebook_ads_account); 

      $available_creatives = $adset->getAdCreatives($creative::getFields()); 

      $current_creative = null; 

      if (!empty($available_creatives)) { 
       foreach ($available_creatives as $creative) { // loops through adsets 
        if ($creative->name == 'Creative of '.$item['title']) { // If adset name matches the name given to new campaign, created campaign is then used 
         $current_creative = $creative; 
        } 
       } 
      } 

      if (!is_null($current_creative)) { 
       $creative = $current_creative; 
      } else { 

       $creative = new Object\AdCreative(null, $this->current_facebook_ads_account); 
       $creative->setData(array(
        Object\Fields\AdCreativeFields::NAME => 'Creative of '.$item['title'], 
        Object\Fields\AdCreativeFields::TITLE => $item['title'], 
        Object\Fields\AdCreativeFields::BODY => $item['properties']['description'], 
        Object\Fields\AdCreativeFields::IMAGE_HASH => $image->hash, 
        Object\Fields\AdCreativeFields::LINK_URL => ipConfig()->get('globalPortalUrl'), 
        Object\Fields\AdCreativeFields::OBJECT_URL => ipConfig()->get('globalPortalUrl'), 
       )); 
       **$creative->create();** 
      } 
      echo 'Creative ID: ' . $creative->id . " <br>\n"; 
     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 
     } 


     /** 
     * Step 7 Create an Ad 
     * 
     * Then, use the image hash returned from above. Finally, create your ad along with ad creative. 
     * Please note that the ad creative is not created independently, rather its data structure 
     * is appended to the ad group 
     * 
     * @link https://developers.facebook.com/docs/marketing-api/reference/adgroup 
     */ 
     try { 

      $ad = new Object\Ad(null, $this->current_facebook_ads_account); 

      $last_ad = $adset->getAds($ad::getFields())->end()->exportData(); 

      //var_dump($last_ad); exit(); 

      $ad->setData(array(
       Object\Fields\AdFields::NAME => $item['title'].' #1', 
       Object\Fields\AdFields::ADSET_ID => $adset->id, 
       Object\Fields\AdFields::CREATIVE => array('creative_id' => $creative->id), 
      )); 
      $ad->create(array(
       Object\Ad::STATUS_PARAM_NAME => Object\Ad::STATUS_PAUSED, 
      )); 
      echo 'Ad ID:' . $ad->id . " <br>\n"; 

     } catch (\Exception $e) { 
      return $this->AdvertisingRenderErrorMessage($e); 

     } 

मैं अपने व्यवसाय के खाते में और कहा कि उस पृष्ठ सौंपा ऐप जो क्वेरी के माध्यम से गुजरता है, उपयोगकर्ता व्यवसाय खाते, ऐप और पेज का मालिक होता है।

पृष्ठ आईडी प्रदान किए जाने पर और क्या चाहिए? अभियान उद्देश्य है:

Object\Fields\CampaignFields::OBJECTIVE => Object\Values\CampaignObjectiveValues::LINK_CLICKS 

मैं वैध PAGE_ID का उपयोग करें।

Object\Fields\AdSetFields::PROMOTED_OBJECT => (object) array(
    Object\Fields\AdPromotedObjectFields::PAGE_ID => '178698438995498', 
) 

या देखते हैं अनुप्रयोग, पेज और व्यापार खाते की सेटिंग्स के साथ समस्याओं: मैं मैं के लिए कुछ अतिरिक्त डेटा (FYI बिना (वस्तु) typehint इस कोशिश की) याद कर रहा हूँ?

कृपया कोई मेरी कॉल का उत्तर दें। लगभग हर चीज का प्रयास इस बिंदु को पार नहीं कर सकता है। कोई अन्य प्रचारित वस्तु अभियान उद्देश्य के साथ काम नहीं करती है।

पीएस 1500 से अधिक प्रतिष्ठा वाले किसी व्यक्ति को कृपया फेसबुक-php-ads-sdk टैग बनाएं।

+1

क्या आपको इसका समाधान मिला? – aks

+0

हाँ, लेकिन मुझे यह याद नहीं है, मुझे लगता है कि यह छवि पर परम के रूप में अमान्य स्थिर सेट के कारण था, मेरे पास एक कार्य कोड है। अगर आपको मुझे दोपहर की जरूरत है। :-) पी एस यदि आप निरंतर स्वचालित विज्ञापन करने की योजना बना रहे हैं तो व्यवसाय खाते या किसी चीज़ के लिए Google से बात करें, वे खाते में सीमाएं बढ़ाएंगे। लेकिन मैं अब यह देखने की कोशिश करूंगा कि कल क्या अलग है, यह कल से पहले था, क्योंकि अब मैं वास्तव में व्यस्त हूं। – juslintek

उत्तर

1

मुझे नहीं लगता कि प्रचारित ऑब्जेक्ट LINK_CLICKS उद्देश्य के लिए आवश्यक है। क्या आपने इसे बिल्कुल सेट करने की कोशिश नहीं की है?

विज्ञापन सेट, खंड बनाने के लिए Facebook docs, क्षेत्र promoted_object

कुछ बोली लगाने का

साथ आवश्यक कहते हैं और LINK_CLICKS उद्देश्य वहाँ सूचीबद्ध नहीं है।


वैकल्पिक रूप से आप अमेरिकन प्लान इंटरफेस (विज्ञापन प्रबंधक या बिजली संपादक) के माध्यम से वांछित पैरामीटर के साथ एक विज्ञापन बनाने और उसके बाद देखने के लिए क्या क्षेत्रों भर रहे हैं और क्या मूल्यों का उपयोग किया गया एपीआई के माध्यम से अपने मूल्यों को वापस पढ़ सकते हैं।

+0

मैं LINK_CLICKS उद्देश्य का उपयोग कर रहा हूं और मैं वही देख रहा हूं "आपके अभियान में आपके उद्देश्य से संबंधित प्रचार ऑब्जेक्ट के साथ एक विज्ञापन सेट शामिल होना चाहिए (उदा: पृष्ठ, यूआरएल, घटना)। कृपया जारी रखने के लिए अपना विज्ञापन सेट अपडेट करें। "जब मेरे नए विज्ञापन को /विज्ञापनों पर पोस्ट किया जाता है। – Kirby

1

मुझे यह त्रुटि हो रही थी क्योंकि मैं एक एड्रेक्रेटिव बनाते समय गलत पैरामीटर नाम का उपयोग कर रहा था।मैं object_id के बजाय page_id का उपयोग कर रहा था।

उम्मीद है कि यह किसी की मदद कर सकता है।

संबंधित मुद्दे