将自定义受众群体链接到Adset

时间:2015-11-24 11:23:33

标签: php facebook facebook-ads-api facebook-marketing-api

我正在使用Facebook营销Api来制作广告和自定义受众群体。我怎么也找不到将创建的自定义受众链接到Adset的方法。 以下是github中提供的示例。目前我只能创建有兴趣和地理位置的广告。

如下例所示,我们只能根据兴趣和地理位置进行定位。

$results = TargetingSearch::search(
  $type = TargetingSearchTypes::INTEREST,
  $class = null,
  $query = 'facebook');
// we'll take the top result for now
$target = (count($results)) ? $results->current() : null;
echo "Using target: ".$target->name."\n";
$targeting = new TargetingSpecs();
$targeting->{TargetingSpecsFields::GEO_LOCATIONS}
  = array('countries' => array('GB'));
$targeting->{TargetingSpecsFields::INTERESTS} = array(
    array(
        'id' => $target->id,
        'name' => $target->name,
    ),
);


$adset = new AdSet(null, $account->id);
$adset->setData(array(
  AdSetFields::NAME => 'My First AdSet',
  AdSetFields::CAMPAIGN_ID => $campaign->id,
  AdSetFields::STATUS => AdSet::STATUS_ACTIVE,
  AdSetFields::DAILY_BUDGET => '150',
  AdSetFields::TARGETING => $targeting,
  AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH,
  AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::START_TIME =>
    (new \DateTime("+1 week"))->format(\DateTime::ISO8601),
  AdSetFields::END_TIME =>
    (new \DateTime("+2 week"))->format(\DateTime::ISO8601),
));
$adset->validate()->create();
echo 'AdSet  ID: '. $adset->id . "\n";

我的要求是将自定义受众群体直接关联到Adset AdSetFields :: CUSTOMAUDIENCE => $ audienceid

这至少可能吗?如果不能,我们如何将我们创建的自定义受众与Adset相关联?

1 个答案:

答案 0 :(得分:1)

您可以使用字段custom_audiences接受一组要定位的自定义受众群体。我不确定这个名字是否也是必需的,但是在所有例子中都是如此:

$targeting->{TargetingSpecsFields::CUSTOM_AUDIENCES} = array(
  array(
    'id' => <AUDIENCE_ID>,
    'name' => <AUDIENCE_NAME>,
  ),
);

查看targeting doc并搜索“定位自定义受众群体和合作伙伴类别”