我正在尝试通过Facebook Marketing API创建广告。 最后一步-广告创建无效,我找不到问题。
以下是用于创建广告的代码:
/**
* @param RequestContract $request
* @param Ad $runner
* @return ResponseContract
* @throws \Exception
*/
public function run(RequestContract $request, AbstractCrudObject $runner): ResponseContract
{
$this->configureCreative($request);
$runner->setData([
AdFields::NAME => $request->getItem('[ad][name]'),
AdFields::ADSET_ID => $request->getItem('[facebook][adset_id]'),
AdFields::CREATIVE => $this->creative,
]);
$graphResponse = $runner->create(array(
Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED,
));
return new ResponseGraph($graphResponse);
}
private function configureCreative(RequestContract $request) : void
{
$linkData = new AdCreativeLinkData();
$linkData->setData(array(
AdCreativeLinkDataFields::LINK => $request->getItem("[ad][link]"),
AdCreativeLinkDataFields::CALL_TO_ACTION => [
'type' => AdCreativeCallToActionTypeValues::APPLY_NOW
],
AdCreativeLinkDataFields::PICTURE => $request->getItem('[ad][image_url]'),
));
$adCreativeObjectStorySpec = new AdCreativeObjectStorySpec();
$adCreativeObjectStorySpec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => $request->getItem('[ad][page_id]'),
AdCreativeObjectStorySpecFields::LINK_DATA => $linkData,
//AdCreativeObjectStorySpecFields::INSTAGRAM_ACTOR_ID => ??? TODO add?
));
$this->creative->setData([
AdCreativeFields::TITLE => $request->getItem("[ad][title]"),
AdCreativeFields::BODY => $request->getItem("[ad][message]"),
AdCreativeFields::OBJECT_STORY_SPEC => $adCreativeObjectStorySpec
]);
}
通过测试请求,我发现问题出在配置中的AdCreativeLinkDataFields::PICTURE
字段。
在使用一些450x450像素的示例图片进行测试时,它可以正常工作。 尝试传递尺寸为1200 x 628像素的真实图像(如Facebook建议)时,我收到异常
FacebookAds\Http\Exception\AuthorizationException: Unsupported post request.
我尝试将图像尺寸调整为628 x 628-同样的错误。 试图将其托管在其他服务器上-无效。
尝试卷曲:
curl \
-F 'name=Trial Company ' \
-F 'adset_id=xxxx' \
-F 'creative={"title":"Trial Company Inc","body":"xxx","object_story_spec":{"page_id":"xxxxxxxx","link_data":{"link":"link","call_to_action":{"type":"APPLY_NOW"},"picture":"link"}}}' \
-F 'status=PAUSED' \
-F 'access_token=xxxxxx' \
-F 'appsecret_proof=xxxxx' \
https://graph.facebook.com/v3.2/act_{id}}/ads
获取错误:
{"error":{"message":"Unsupported post request.","type":"GraphMethodException","code":100,"fbtrace_id":"AtGSfGrLe42"}}
没有任何解释为什么会发生此错误。
更新:为当前图像创建了AdImage-没有发生错误。尝试在image_hash
中使用LINK_DATA
而不是picture
-发生相同的错误。