我正在尝试构建一项服务,让用户根据我们的电子邮件数据库创建自定义受众群体的Facebook广告。
在制作facebook广告之前,我想制作广告预览。当我使用我自己的帐户(管理Facebook应用程序)登录时,这可以正常工作,但在以测试用户身份登录时失败。
这是用户将要做的事情: 1.访问该服务的网站。 2.使用范围为Facebook帐户登录:public_profile,email,manage_pages,publish_pages,business_management,ads_management 3.选择要使用的Facebook页面 4.创建AdCreative。由此可以进行广告预览。但它无法创建Adcreative并给我以下错误:
"error":{"message":"Application does not have permission for this action","type":"OAuthException","code":10,"error_subcode":1341012,"is_transient":false,"error_user_title":"No permission to access this profile","error_user_msg":"You don't have required permission to access this profile","fbtrace_id":"EgTeMOXPCUp"}}
访问令牌和广告帐户属于Facebook应用。我也尝试使用网页访问令牌,但我无权访问该广告帐户。 这是代码:
function fbadcreative($url, $message, $carasoul, $fbtoken, $pageid){
$calength = count($carasoul);
$children = array();
for($i = 0; $i < $calength; $i++){
$caitem = $carasoul[$i];
$caitem['hash'] = fbaddimage($caitem['picture'], $caitem['id']);
$child = (new AdCreativeLinkDataChildAttachment())->setData(array(
AdCreativeLinkDataChildAttachmentFields::LINK => $caitem['link'],
AdCreativeLinkDataChildAttachmentFields::NAME => $caitem['name'],
AdCreativeLinkDataChildAttachmentFields::DESCRIPTION => $caitem['description'],
AdCreativeLinkDataChildAttachmentFields::IMAGE_HASH => $caitem['hash'],
));
$children[] = $child;
}
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
AdCreativeLinkDataFields::LINK => $url,
AdCreativeLinkDataFields::CAPTION => $url,
AdCreativeLinkDataFields::MESSAGE => $message,
AdCreativeLinkDataFields::MULTI_SHARE_END_CARD => false,
AdCreativeLinkDataFields::MULTI_SHARE_OPTIMIZED => false,
AdCreativeLinkDataFields::CHILD_ATTACHMENTS => $children,
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => $pageid,
AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));
$creative = new AdCreative(null, 'act_<accountid>');
$creative->setData(array(
AdCreativeFields::NAME => $url,
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
try {
$creative->create();
return $creative->id;
//return $creative->read(array(AdCreativeFields::ID,));
} catch (FacebookAds\Http\Exception\AuthorizationException $e) {
echo 'Message: ' . var_dump($e);
$previousException = $e->getPrevious();
// Do some further processing on $previousException
exit;
}
答案 0 :(得分:4)
我知道这是一篇较旧的文章,但是其他人可能会读到如何解决这个问题。
您需要为通过api请求广告的用户提供广告并分析将为其创建广告素材的PAGE上的权限。
在此处使用图形浏览器的示例请求:
page_id/assigned_users?user=system_user_id&tasks=['ADVERTISE', 'ANALYZE']
答案 1 :(得分:0)
在我的情况下,由于输入错误的页面ID,我也遇到了同样的错误。我给出的另一个页面ID与该广告帐户没有关联。