目標設定說明

取得一組人類易讀的目標設定規格。若要讀取特定 ads 的目標設定說明,請向 https://graph.facebook.com/{AD_ID}/targetingsentencelines 進行 HTTP GET

現有廣告的目標設定說明

若要取得現有廣告的 targetingsentencelines 連結,請執行以下操作:

use FacebookAds\Object\Ad;

$ad = new Ad(<AD_ID>);
$targeting_description = $ad->getTargetingDescription();

// Output targeting description
foreach ($targeting_description->targetingsentencelines as $description) {
  echo $description['content'].PHP_EOL;
  foreach ($description['children'] as $child) {
    echo "\t".$child.PHP_EOL;
  }
}
from facebookads.adobjects.ad import Ad

ad = Ad(<AD_ID>)
targeting_description = ad.get_targeting_sentence_lines().get_one()

# Output the targeting description
for description in targeting_description['targetingsentencelines']:
    print(description['content'])
    for child in description['children']:
        print("\t" + child)
curl -G \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.5/<AD_ID>/targetingsentencelines

回應:

{
    "id": "<AD_ID>/targetingsentencelines",
    "targetingsentencelines": [
    {
        "content": "Location - Living In:",
        "children": [
            "Japan",
            "United States"
        ]
    },
    {
        "content": "Age:",
        "children": [
            "20 - 24"
        ]
    },
    {
        "content": "Gender:",
        "children": [
            "Male"
        ]
    }]
}

回應包含以下欄位:

名稱 說明

id

類型:字串

targetingsentencelines 的編號。

targetingsentencelines

類型:JSON 物件陣列

人類易讀的目標設定規格說明。每個物件都包含 content 或目標設定類型,以及 children 或目標設定規格。此欄位僅考慮有效版位

廣告帳號的目標設定說明

您還可以透過 https://graph.facebook.com/{AD_ACCOUNT_ID}/targetingsentencelines 取得廣告帳號的目標設定說明和具有 HTTP GET 的目標設定規格。

例如,以下內容可取得居住在美國或日本且年齡在 20-24 歲之間的男性用戶的目標設定說明:

use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$targeting = new Targeting();
$targeting->setData(array(
  TargetingFields::GEO_LOCATIONS => array(
    'countries' => array('US', 'JP')
  ),
  TargetingFields::GENDERS => array(1),
  TargetingFields::AGE_MIN => 20,
  TargetingFields::AGE_MAX => 24,
));

$params = array(
  'targeting_spec' => $targeting->exportData(),
);

foreach ($account->getTargetingSentenceLines(array(), $params) as $description) {
  echo $description->{'content'}.PHP_EOL;
  foreach ($description->{'children'} as $child) {
    echo " - ".$child.PHP_EOL;
  }
}
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.targeting import Targeting

account = AdAccount('act_<AD_ACCOUNT_ID>')
params = {
    'targeting_spec': {
        Targeting.Field.geo_locations: {
            Targeting.Field.countries: ['US', 'JP'],
        },
        Targeting.Field.genders: [1],
        Targeting.Field.age_min: 20,
        Targeting.Field.age_max: 24,
    },
}

targeting_description = account.get_targeting_sentence_lines(params=params) \
    .get_one()

# Output the targeting description
for description in targeting_description['targetingsentencelines']:
    print(description['content'])
    for child in description['children']:
        print("\t" + child)
curl -G \
  --data-urlencode 'targeting_spec={ 
    "age_max": 24, 
    "age_min": 20, 
    "genders": [1], 
    "geo_locations": {"countries":["US","JP"]} 
  }' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/targetingsentencelines

回應:

{
    "params": {
        "genders": [1],
        "age_min": 20,
        "age_max": 24,
        "geo_locations": {
            "countries": [
                "US",
                "JP"
            ]
        }
    },
    "targetingsentencelines": [{
        "content": "Location - Living In:",
        "children": [
            "Japan",
            "United States"
        ]
    }, {
        "content": "Age:",
        "children": [
            "20 - 24"
        ]
    }, {
        "content": "Gender:",
        "children": [
            "Male"
        ]
    }]
}

其他參數包括:

名稱 說明

targeting_spec

類型:JSON 物件

必要項目

取得此目標設定規格的目標設定說明。

hide_targeting_spec_from_return

類型:布林值

選用。

回應是否已要求包括的 targeting_spec。預設為 false

回應包含以下欄位:

名稱 說明

targetingsentencelines

類型:JSON 物件陣列

人類易讀的目標設定規格說明。每個物件都包含 content 或目標設定類型,以及 children 或目標設定規格。

params

類型:JSON 物件

您提供的目標設定規格。