简体   繁体   English

如何使用 php 为广告创意制作 Facebook 营销 API?

[英]How to make Facebook Marketing API for Ad Creative using php?

I am trying to create an ad creative but getting an invalid parameter error.我正在尝试创建广告素材,但收到无效参数错误。 The exception even does not specify which parameter is wrong.该异常甚至没有指定哪个参数是错误的。

try {
     $link_data = new AdCreativeLinkData();
     $link_data->setData(array(
           AdCreativeLinkDataFields::MESSAGE => 'try it out',
           AdCreativeLinkDataFields::LINK => 'http://www.google.com',
           AdCreativeLinkDataFields::IMAGE_HASH => '704e55dbf724243acfb8457a4f68a92a',
         ));
    
     $object_story_spec = new AdCreativeObjectStorySpec();
     $object_story_spec->setData(array(
           AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
     ));
    
     $creative = new AdCreative(null, 'act_576834712392068');
    
     $creative->setData(array(
           AdCreativeFields::NAME => 'Sample Creative Suite CRM',
           AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
     ));
     $creative->create();
} 
catch (Exception $e) {
  echo 'Caught exception: ',  $e, "\n";
}

Caught exception: exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter'捕获的异常:带有消息“无效参数”的异常“FacebookAds\Http\Exception\AuthorizationException”

It seems you have not added the Page where the creative has to be posted.您似乎没有添加必须发布广告的页面。 I think adding AdCreativeObjectStorySpecFields::PAGE_ID => 'your published page id here' in object_story_spec array will resolve your problem.我认为在object_story_spec array中添加AdCreativeObjectStorySpecFields::PAGE_ID => 'your published page id here'将解决您的问题。

Don't forget to set your app's status to active from development.不要忘记将您的应用程序的状态设置为从开发中激活。 It was the reason of the same failure.这也是同样失败的原因。 You can check your error in more detail with您可以使用以下方法更详细地检查您的错误

catch (Exception $e) {
    var_dump($e)
}

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

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