繁体   English   中英

Facebook 营销 API 放置资产自定义asset_feed_spec错误

[英]Facebook Marketing API Placement asset customization asset_feed_spec error

我一直在尝试根据展示位置(facebook-feed、messenger-story)自动生成具有不同内容的广告。 我一直在尝试遵循文档。

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

但是由于某种原因,它返回一个错误,指出整个 object_story_spec 是错误的。 但这可能与我的asset_feed_spec 有关,因为这是我唯一改变的东西。

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

有没有人尝试过这样做? 或者有什么办法让我得到更清晰的错误信息?

这是我在尝试创建广告素材时使用的代码。

$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)
]);

为了使其更具可读性,我创建了一个 function 来创建不同的资产提要规范。 要更好地理解它,请参阅文档中的示例。

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()
    ];
}

我还分离了asset_customization_rules 以使其更易于理解。

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'
            ]
        ]
    ];
}

要生成广告素材,您需要传递带有有效 page_id 的 object_story_spec,如下所示,

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

它应该在提供有效的 page_id 后工作,它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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