PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] Unable to modify Ad Creative URL tags using Facebook PHP SDK

 February 04, 2022     facebook, facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

I have been facing an issue while updating Ad Creative URL tags.

I knew that we can't update URL tags for already existing Ad Creative.

So, I tried to clone existing one with modified URL tags and tried to remove old one but deleting create issues and now I'm getting this error.

You cannot delete this creative because it is currently in use for existing adgroups

Tried to change ad status to "DELETED" but that also don't works. Also, tried to change the Ad status to "PAUSED" but no luck at all. Even API don't update Ad status.

Anyone, please guide me what to do to resolve this? Or any other way through which I can update Ad Creative URL tags?

I am using PHP SDK and following this FB documentation. I have all required permissions for my application and also they are approved by FB.


Solution

I successfully did this by following these steps

  1. Create new Ad Creative with required values
  2. Assign this new Ad Creative to the "Ad" to which old Ad Creative was attached

Following is the PHP code I used to fix this issue.

$newObj = new AdCreative(null, 'act_account_id');
    $newData = [];
    $fields = [
        AdCreativeFields::NAME,
        AdCreativeFields::TITLE,
        AdCreativeFields::BODY,
        AdCreativeFields::OBJECT_URL,
        AdCreativeFields::LINK_URL,
        AdCreativeFields::IMAGE_HASH,
        AdCreativeFields::OBJECT_STORY_ID,
        AdCreativeFields::OBJECT_STORY_SPEC,
        AdCreativeFields::URL_TAGS,
    ];
    foreach ($fields as $field) {
        $value = $oldAdCreative->{$field};
        if(isset($newValues[$field])){
            $value = $newValues[$field];
        }
        $newData[$field] = $value;
    }
    $newObj->setData($newData);
    $newObj->create();

    // Assigning New Creative ID to Ad
    $ad = new Ad($adId);
    $ad->update(array(
        'creative' => ['creative_id' => $newObj->{AdCreativeFields::ID}],
        'redownload' => true,
    ));

Done.



Answered By - Bilal Iqbal
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing