简体   繁体   中英

Facebook Marketing API Placement asset customization asset_feed_spec error

I'v been trying to automatically generate ads with different content based on the placements (facebook-feed, messenger-story). I'v been trying to follow the documentation.

https://developers.facebook.com/docs/marketing-api/dynamic-creative/placement-asset-customization#asset-feed

But for some reason, it returns an error saying that the entire object_story_spec is wrong. But this probably has to do something with my asset_feed_spec, because it's the only thing I have been changing.

object_story_spec param is invalid
Object story spec is ill formed. Maybe missing Page ID or creative details, or invalid fields exist

Have anyone tried to do this before? Or is there any way for me to get a clearer error message?

Here is the code I'm using when trying to create the creative.

$creative->setData([
   AdCreativeFields::CALL_TO_ACTION_TYPE => $callToAction,
   AdCreativeFields::IMAGE_HASH => $image_hash,
   AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
   AdCreativeFields::ASSET_FEED_SPEC => $this->getAssetFeedSpec($post_message, $link_url, $headline, $image_hash, $description)
]);

To make it a bit more readable, I created a function that creates the different Asset feed specifications. To understand it a bit better, see the example in the documentation.

https://developers.facebook.com/docs/marketing-api/dynamic-creative/placement-asset-customization#supported-fields

public function getAssetFeedSpec($post_message, $link_url, $headline, $image_hash, $description) {
    return [
      'images' => [
        [
          'hash' => $image_hash
        ]
      ],
      'bodies' => [
        [
          'adlabels' => [
              [
                'name' => 'labelfirst',
              ]
          ],
          'text' => $post_message
        ],
        [
          'adlabels' => [
              [
                'name' => 'labelsecond',
              ]
          ],
          'text' => $headline
        ]
      ],
      'titles' => [
        [
          'text' => $headline
        ]
      ],
      'descriptions' => [
        [
          'text' => $description
        ]
      ],
      'ad_formats' => [
        'SINGLE_IMAGE'
      ],
      'call_to_action_types' => [
        'LEARN_MORE'
      ],
      'link_urls' => [
        [
          'website_url' => $link_url
        ]
      ],
      'videos' => [],
      'asset_customization_rules' => $this->getAssetCustomizationRules()
    ];
}

I also separated the asset_customization_rules to make that a bit more understandable.

public function getAssetCustomizationRules() {
    return [
        [
            'customization_spec' => [
                'publisher_platforms' => [
                    'facebook',
                    'instagram',
                    'audience_network',
                    'messenger'
                ],
                'facebook_positions' => [
                    'feed',
                ],
                'instagram_positions' => [
                    'stream'
                ],
                'audience_network_positions' => [
                    'classic'
                ]
            ],
            'body_label' => [
                'name' => 'labelfirst'
            ]
        ],
        [
            'customization_spec' => [
                'publisher_platforms' => [
                    'messenger'
                ],
                'messenger_positions' => [
                    'stream'
                ]
            ],
            'body_label' => [
                'name' => 'labelsecond'
            ]
        ]
    ];
}

To generate creative, you need to pass object_story_spec with valid page_id just like below,

{
"object_story_spec": {
    "page_id": "10506210208xxx"
},
"asset_feed_spec": {
    "videos": [
        {
            "adlabels": [
                {
                    "name": "placement_asset_3667064314xxx"
                }
            ],
            "video_id": "3667064314xxx"
        },
..

It should work after providing a valid page_id, It's working for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM