Marketing API Version

Targeting Specs

Overview

Targeting specs are used as part of ad sets to define the type of person the ad will be displayed to. You may choose to define audiences using Facebook's native targeting offerings, your own list of people using our Custom Audiences and lookalike audience feature, or 3rd party Partner Categories.

There are a large number of available fields for use in targeting specs so we have split them by category below. Any combination of targeting may be used, and combinations will be OR-ed together by default.

Please note that at least one of the following is required right under targeting (ie. outside of flexible_spec):

  • geo_locations: geographical targeting field from country, region, city or zip
  • custom_audiences
  • product_audience_specs
  • dynamic_audience_ids

Demographics and events

NameTypeDescription

genders

array

Indicates gender-based targeting.

1=male

2=female.

Defaults to all.

age_min

int

Minimum age. If used, must be 13 or higher. If omitted, will default to 18

age_max

int

Maximum age. If used, must be 65 or lower.

Location

Search parameters are used to retrieve values for location targeting. See the targeting search API for information about getting values for location.

Location Targeting requires two parameters: geo_locations to specify the locations you wish to target and optionally excluded_geo_locations to exclude some areas targeted by the geo_locations provided.

We are launching country_groups as a new type for geo_locations. This will enable advertisers to target broader geographic regions such as Europe, North America, etc.

The values accepted for both parameters follow the same format:

NameTypeDescription

countries

array

Values for country targeting. It must be an array of country codes. See targeting search API. Example: 'countries': ['US']

regions

array

State, province, or region. To get the available values, see targeting search API. Limit: 200 regions.
Example: 'regions': [{'key':'3847'}]

cities

array

Specify the key, radius & distance_unit. For the key values, see targeting search API. radius is a number around cities, limits are 10 to 50 miles or 17 to 80 kilometers. distance_unit is mile or kilometer. Limit: 250 cities.
Example: 'cities': [{'key':'2430536', 'radius':12, 'distance_unit':'mile'}]

zips

array

Zip Codes for targeting. see targeting search API. Limit: 2500 Zips
Example: 'zips':[{'key':'US:94304'},{'key':'US:00501'}]

custom_locations

array of objects

Available in all objectives. It requires you to specify an exact location in latitude/longitude or specify an address line as the center of your targeted area. You also need to specify a radius for your location, limits from .63 to 50 miles, or 1 to 80 kilometers. distance_unit can be in miles or kilometers. The default distance_unit is mile. Limit: 200 addresses. Note that PO Box is not supported in the address_string. Only the physical address can be passed.
Example 'custom_locations':[{'address_string': '1601 Willow Road, Menlo Park, CA', 'radius': 5},{'latitude': 36, 'longitude': -121.0, 'radius': 5, 'distance_unit': 'kilometer'},]

latitude

float

Latitude of the location

longitude

float

Longitude of the location

name

string

Descriptive name for the address. This can be used in conjunction with the latitude and longitude values for geo location targeting even when the address_string is not provided

radius

float

Radius around the latitude/longitude, expressed in miles unless set in the distance_unit field. The limits of the radius are 0.63 to 50 miles, or 1 to 80 kilometers.

distance_unit

string

Optional value of kilometer or mile, defaults to mile

address_string

string

Address corresponding to the latitude/longitude. e.g. 1601 Willow Rd, Menlo Park, CA. The suggested address format is: street number street name, city, state/province, country. Please do not include the postal code in the address_string.

geo_markets

array of objects

Specify the key for the market. We support all designated market areas (DMA) and the key is in the format “DMA:501”. The DMA code can be retrieved from the Targeting Search endpoint by querying by the name of the DMA. Limit: 2500
Example 'geo_markets':[{'key': 'DMA:501', 'name': 'New York'},{'key': 'DMA:543', 'name': 'Springfield-Holyoke'},]

electoral_district

array

Specify the key for electoral districts. The district key can be retrieved from the Targeting Search API.
Example: 'electoral_districts':[{'key':'US:AK00'},{'key':'US:CA01'},{'key':'US:NY14'}]

location_types

array of string values

Possible values are:
recent: People whose most recent location is the selected area, as determined by information from their mobile device. This value is not available when excluding location types.
home: People whose stated location from their Facebook profile “current city” is within that location. This is also validated by IP address and aggregated information from their friends’ stated profile locations.
travel_in: People whose most recent location is the selected area, as determined by information from their mobile device, and are more than 100 miles away from their stated current city from their Facebook profiles. This value is not available when excluding location types.
Please Note:

  • If location_types is not specified, the default value is ['home'].
  • travel_in cannot be used with other values in the location_types.
  • If you want to target “everyone in this location”, you need to add both recent and home in the location_types field.

Examples:

'location_types':['recent', 'home']

'location_types':['travel_in']

country_groups

array of string values

Values for targeting countries in global geographical regions and free trade areas. It must be an array of country group codes. Possible values are:
worldwide: for Worldwide.
africa: for Africa.
south_america: for South America.
central_america: for Central America.
caribbean: for Caribbean.
north_america: for North America.
europe: for Europe.
asia: for Asia.
oceania: for Oceania.
eea: for European Economic Area.
nafta: for North American Free Trade Agreement.
afta: for ASEAN Free Trade Area.
mercosur: for MERCOSUR.
gcc: for Gulf Cooperation Council.
apec: for Asia-Pacific Economic Cooperation.
cisfta: for Commonwealth of Independent States Free Trade Area.
See targeting search API. Example: 'country_groups': ['asia','mercosur']

Mobile

Mobile targeting options are particularly useful for mobile app install ads.

NameTypeDescriptionMobile app ad

user_os

array

Accepts one or more values from the OS option table below. You can get these values from the /search end-point with parameters type=adTargetingCategory and class=user_os. Note you cannot target the minimum version of one platform with the other platform. However you can target both platforms without specifying minimal versions of either.
Valid Examples
- ['iOS', 'Android']
- ['iOS']
- ['Android_ver_4.2_and_above']
- ['iOS_ver_8.0_to_9.0']
Invalid Examples
- ['Android', 'iOS_ver_8.0_and_above']
- ['iOS', 'Android_ver_4.0_and_above']

Required

user_device

array

Devices listed here must match the value specified in user_os. Possible values can be retrieved using the /search end-point with parameters type=adTargetingCategory and class=user_device.

Not Required

excluded_user_device

array

List of devices to exclude. Devices listed here must match the value specified in user_os. Possible values can be retrieved using the /search end-point with parameters type=adTargetingCategory and class=user_device.

Not Required

wireless_carrier

array

Allowed value is Wifi. This will allow you to target mobile users who are currently on wifi networks.

Not Required


OS optionTypeDescription

iOS

string

iOS devices, including iPhone, iPad, and iPod

iOS_ver_x.x_and_above

string

iOS devices running OS versions x.x and above. Values are: 2.0, 3.0, 4.0, 4.3, 5.0, 6.0, 7.0, 8.0, 9.0. e.g. iOS_ver_4.0_and_above

iOS_ver_x.x_to y.y

string

iOS devices running OS versions x.x to y.y. Values are: 2.0, 3.0, 4.0, 4.3, 5.0, 6.0, 7.0, 8.0, 9.0. x.x version must be less than y.y version. e.g. iOS_ver_8.0_to_9.0

Android

string

Android devices

Android_ver_x.x_and_above

string

Android devices running Android versions x.x and above. Values are: 2.0, 2.1, 2.2, 2.3, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2., 4.3, 4.4, 5.0, 5.1. e.g. Android_ver_4.0_and_above

Android_ver_x.x_to y.y

string

Android devices running Android versions x.x to y.y. Values are: 2.0, 2.1, 2.2, 2.3, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2., 4.3, 4.4, 5.0, 5.1. x.x version must be less than y.y version. e.g. Android_ver_4.2_to_5.0

Within the same targeting spec field, categories are combined together (i.e. iPod OR iPad OR iPhone). Between targeting spec fields and BCTs, the intersection of all groups is taken.

Note: The above categories are not mutually exclusive, so if iOS is selected you will get all devices that run iOS (such as iPhone and iPod) without having to specify user_device.

Placement

You can deliver your ads in specific placements, e.g., desktop News Feed only, or mobile News Feed plus Audience Network.

Page Types

With v2.6 or earlier, you can set page_types in the targeting specs of your ad set. With v2.7, you can only read the page_types, but cannot set it during creation or update. And it will not be readable after v2.7. Three new fields, device_platforms, publisher_platforms, and facebook_positions, described below, should be used instead.

If you do not specify any placement targeting, the default placements will be selected accordingly to your campaign objective. The current default placement page_types include desktopfeed, rightcolumn, mobilefeed, instagramstream, and mobileexternal. Note that the default placements may change by Facebook in the future without notice.

NameTypeDescription

page_types

array

Array of one or more strings of the following value:

desktopfeed: News Feed on Facebook Desktop

rightcolumn: Right column on Facebook Desktop

mobilefeed: News Feed on Facebook Mobile. Note: Video ads within Mobile News Feed are also eligible to appear in suggested video feeds.

instagramstream: The stream of media on Instagram mobile app. More details on Instagram Ads doc.

mobileexternal: Audience Network. Note that this page type must be selected with mobilefeed.

home: Exclusively on right column on Facebook Desktop News Feed (only available for Premium)

On Audience Network, you may want to limit which publishers display your ads. You can exclude publishers by category, detailed below. Alternatively, you can create a custom list of app store URLs or domain URLs and exclude them.

NameTypeDescription

excluded_publisher_categories

array

Array of strings values of the following category names:
Religion
Politics
Dating
Gambling
e.g. "excluded_publisher_categories": ["Religion", "Politics"]

excluded_publisher_list_ids

array

Array of numeric strings. Each string is a custom list ID for a list of exclusions. You can create custom lists through Power Editor or through the API
e.g. "excluded_publisher_list_ids":["<block_list_id_1>","<block_list_id_2>"]

Depending on the campaign objective, only certain placement options are allowed. See the validation documentation for mapping.

Device, Publisher, and Positions

To specify where you want to deliver your ads, use three Targeting Specs subfields for an ad set: device_platforms, publisher_platforms, and facebook_positions. All supported versions of Marketing API have these subfields. When you read targeting specs for your ad set, you see these new subfields, even if you originally created it with page_types in version 2.6 or earlier.

Use device_platforms to specify on what kind of device the user should see your ad. Use publisher_platforms to specify the publishing channel such as Instagram. Use xxxxxx_positions to specify which certain positions on a certain publishing channel if there are multiple.

OptionsRequired?DefaultComments

device_platforms

mobile, desktop

No

All

publisher_platforms

facebook, instagram, audience_network, messenger

No

facebook, instagram, audience_network

facebook_positions

feed, right_hand_column, instant_article

No

All

If any value is specified, publisher_platforms needs either to include facebook or to absent. feed includes News Feed of both Desktop and Mobile, also Suggested Video for video ads. If you select instant_article, you must also use feed and on device_platforms, you must use mobile since Instant Articles is mobile only

The logic between options in the same parameter is “OR”. For example, publisher_platforms=['facebook','instagram'] means that you want this ad to be delivered to both Facebook and Instagram. And the logic between parameters is “AND”. For example, publisher_platforms=['facebook']&device_platforms=['mobile'] means that you want this ad to be delivered to Facebook Mobile only. If the final result is empty, like publisher_platforms=['instagram']& device_platforms=['desktop'], you will get a validation error.

All existing validations still apply, such as Audience Network cannot be used by itself.

For example, to use Instant Articles:

curl \
-F 'name=My Ad Set' \
-F 'optimization_goal=REACH' \
-F 'billing_event=IMPRESSIONS' \
-F 'bid_amount=2' \
-F 'daily_budget=1000' \
-F 'campaign_id=<AD_CAMPAIGN_ID>' \
-F 'targeting={"geo_locations":{"countries":["US"]}, "facebook_positions":["feed","right_hand_column", "instant_article"]}' \
-F 'status=ACTIVE' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/<APIVERSION>/act<AD_ACCOUNT_ID>/adsets

Ad sets created in v2.6 or earlier

Please note that some combinations of page_types cannot be represented correctly by device_platforms, publisher_platforms and facebook_positions. For example, an adset created in v2.6 with page_types=['desktopfeed', 'instagramstream'] will be represented by device_platforms=['desktop', 'mobile'] and publisher_platforms=['instagram', 'facebook']. However, if you create a new ad set in v2.7 or up with these values, this would also target Facebook mobile (mobilefeed).

Facebook connections

Connection targeting allows you to target people who are either connected or not connected to your brand.

NameTypeDescription

app_install_state

string

Only applicable when the objective is app related (e.g. MOBILE_APP_*, CANVAS_APP_*), must be used in conjunction with promoted_object at adset level, and can apply to both link and video app ads. Allowed values are

INSTALLED: target users who have the promoted object/app installed.

NOT_INSTALLED: target users who do not have the promoted object/app installed

NONE: same as not specifying.

e.g. 'app_install_state': 'NOT_INSTALLED'

connections

array of 'id' to value or just value
[{'id':123}, {'id':456}, 789]

An array of Facebook IDs. Connections allows you to target your ad sets to people who are a fan of your Page, a member of your Group, RSVP’d to your Event, have logged into your mobile app with Facebook Login, or authorized your Canvas app. The session user has to be an admin of the page, group or event, or developer of the app that is being targeted against. Events that occured in the past cannot be targeted. Limit: 50 connections.

excluded_connections

array of 'id' to value or just value
[{'id':123}, {'id':456}, 789]

An array of Facebook IDs. Enables you to target your ad sets to people who have not become fans of your Page, authorized your Canvas App or have not logged into your mobile app with Facebook Login. If you have global Page, you must use it for exclusion instead of your local country Page, members of your Group, people who RSVP'd to your Event or people who authorized your app. You cannot target events that occurred in the past. To set this, you need to be an admin of the Page, group or event, or developer of the app used. If it is a 'Page Likes' campaign, you need to exclude your page when editing your adset.

friends_of_connections

array of 'id' to value or just value
[{'id':123}, {'id':456}, 789]

An array of Facebook Object IDs. 'Friends of connections' allows you to target friends of the people who are connected to your object. Connections are fans of your Page, members of your Group, and people who have interacted with your app. The session user has to be an admin of the Page, group, or a developer of the app used.

Interests

Interest targeting lets you target everyone who has expressed a specific interest. See targeting search API for information about getting values for all interests.

NameTypeDescription

interests

array

Array of objects with 'id' and (optional) 'name' fields. eg; 'interests':[{id: 6003139266461, 'name': 'Movies'}, {id: 6003139266462}, 6003139266463]

Behaviors

Behavior based targeting is specific to a user's particular action or past purchase behavior, purchase propensity. Examples:

  • Mobile Device Owners (iPhone Owners, Android Owners (All), ...)
  • Travel Behavior (Business Travelers, Intender - Brazil, ...)
  • Partner Categories (DLX > Lifestyles > Gamers, Axciom > Financials > Bank Cards, ...)

See targeting search API for information about getting values for all behavior categories (except Partner Categories). See Partner Categories for information about getting values for all Partner Categories.

NameTypeDescription

behaviors

array

Array of objects with 'id' and (optional) 'name' fields. eg; 'behaviors':[{id: 6004386044572, 'name': 'Android Owners (All)'}, {id: 6004386044573}, 6004386044574]

Advanced Demographics

See targeting search API for information about getting values for demographic targeting.

NameTypeDescription

relationship_statuses

array

Array of integers for targeting based on relationship status.

1: single

2: in_relationship

3: married

4: engaged

6: not specified

7: in a civil union

8: in a domestic partnership

9: In an open relationship

10: It's complicated

11: Separated

12: Divorced

13: Widowed

The default of ALL is used if you specify Null or do not specify the field. Do not specify zero.

interested_in

array

Array of 1 or more integer(s) from below enum for targeting based on the 'interested in' field of the user profile.

1: men

2: women

3: men and women

4: not specified

e.g. 'interested_in':[1]

The default of ALL is used if you specify an empty array. The default of ALL is also used if you do not specify the field. Do not specify zero. Please note 'interested in' targeting is not available in Europe due to local laws.

life_events

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

politics

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

industries

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

income

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

net_worth

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

home_type

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

home_ownership

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

ethnic_affinity

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

generation

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

household_composition

array

Array of objects with (optional) 'id' and 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

moms

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

family_statuses

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

office_type

array

Array of objects with 'id' and (optional) 'name' fields. e.g. [{'id': 123, 'name': 'foo'}, {'id': 456}, 789]

Education and workplace

Search parameters are used to retrieve values for education and workplace targeting. See targeting search API for all options.

NameTypeDescription

education_schools

array

Schools/colleges/institutions. e.g. [{id: 105930651606, 'name': 'Harvard University'}, {id: 105930651607}, 105930651608] Limit: 200 education schools.

education_statuses

array

Array of integers for targeting based on education level.

1: HIGH_SCHOOL

2: UNDERGRAD

3: ALUM

4: HIGH_SCHOOL_GRAD

5: SOME_COLLEGE

6: ASSOCIATE_DEGREE

7: IN_GRAD_SCHOOL

8: SOME_GRAD_SCHOOL

9: MASTER_DEGREE

10: PROFESSIONAL_DEGREE

11: DOCTORATE_DEGREE

12: UNSPECIFIED

13: SOME_HIGH_SCHOOL

college_years

array

Array of integers for graduation year from college. The earliest year is 1980.

education_majors

array

Majors of study. e.g. [{'id': 123, 'name': 'Computer Science'}, {'id': 456}, 789] Limit: 200 education majors.

work_employers

array

Company, organization, or other workplace. e.g. [{'id':'50431654','name':'Microsoft'}, {'id':50431655}, 50431656] Limit: 200 employers.

work_positions

array

Self-declared work positions. e.g. [{'id':105763692790962, 'name':'Business Analyst'}, {'id':105763692790963}, 105763692790964] Limit: 200 work positions.

Custom Audiences

First, create a custom audience and add users to the audience. Then you can use the audience in targeting, either for inclusion or exclusion.

You can include up to 500 custom audiences in custom_audiences.
You can include up to 500 custom audiences in excluded_custom_audiences.

NameTypeDescription

custom_audiences

array

Array of audience IDs or audience objects ('id' field only). e.g. [123, 456] or [{'id': 123}, {'id': 456}]

excluded_custom_audiences

array

Array of audience IDs or audience objects ('id' field only). e.g. [123, 456] or [{'id': 123}, {'id': 456}]

Please note that excluded_custom_audiences in a targeting spec is different from excluded_custom_audiences that can be read from an APP_COMBINATION Custom Audience.

     targeting:{
          "geo_locations":{
            "countries":["US"],
          },
          "age_min":25,
          "age_max":40,
          "custom_audiences":[{"id":6004192254512}]}
          "excluded_custom_audiences":
            [{"id":6004192252847}],
      }

Additional Targeting

The below are additional targeting fields:

NameTypeDescription

locales

array

Locales. To get the available values, see targeting search API. The values are specified as indices; the indices are in a sub-array called 'locales'. Uses of this parameter include for targeting users with a different language than the common language for the specified location parameter; you specify an ID for the language, e.g. 5 for German. Limit: 50 locales. If you set the targeting on an ad set to one of the '1xxx' values, which are virtual 'locales' which represent a group of the other locales, the ad set will actually be set to target the individual locales within that group. You can get the mapping of the virtual 'locales' to language sets via targeting search API with type=adlocale and look at the bottom part of the outputs.

Custom Broad Category Targeting

Broad Categories (BCTs) are used for custom clusters created or permissioned specifically to your account.

NameTypeDescription

user_adclusters

array

Array of ID-name pairs for BCT clusters. See below for information on retrieving BCT's. Limit: 50 ID-name pairs.

To query the broad category targeting of an Ad account, make an HTTP GET call to

https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/broadtargetingcategories

The response will be an array of the following JSON key-value pairs

NameDescriptiontype

id

The id of a broad category that is used for ad targeting spec

long

name

The name of a broad category

string

parent_category

The parent category of a broad category

string

size

Audience size of the broad category

int

type

6=BCT

int

type_name

BCT

string

Targeting expansion

Targeting expansion allows Facebook to expand interests when it may increase conversions at a lower cost action for Direct Response objectives like conversions, mobile app install, and mobile app events.

Note that targeting expansion is not creating a lookalike audience. It does not allow one to change demographic targeting (ex: age or gender), instead it only allow interest expansion.

By default, targeting expansion is enabled. If you wish to opt out of it for a given ad set, you must explicitly turn it off by setting the targeting_optimization parameter to none.

To turn targeting expansion on or off, make a POST request to /adsets.

You can also opt your ad sets out of expanded targeting by setting the targeting_optimization parameter to NONE Request

curl -X POST \
 -F 'targeting={ \
           'targeting_optimization':'expansion_all', \
           'geo_locations':{'countries': ['US']}, \
           'interests': [{'id': 6003139266461}, {'id': 6003714246353}] \
     }' \
 -F 'access_token=<ACCESS_TOKEN>' \
"https://graph.facebook.com/<API_VERSION>/adsets"

If the request succeeds, you get a response as:

{
  "success": true
}

Flexible targeting

Flexible targeting allows you to AND and OR different targeting options to reach a specific set of users specified in the flexible_spec. It also allows you to specify a group of segments to be excluded in exclusions.

All targeting segments inside the flexible_spec are ANDed with all segments outside e.g. age, gender, geo locations.

Within the flexible_spec, each top level array elements are ANDed together and each secondary level array elements are ORed together.

For example, if your flexible spec is as below, the resulting audience is:

(segment 1 or segment2 or segment3) and (segment 4 or segment 5) and segment 6

flexible_spec=
[
  {
    'segment_type':[segment1, segment2], 
    'segment_type':[segment3]
  },
  { 
    'segment_type':[segment4, segment5]
  },
  { 
    'segment_type':[segment6]
  }
]

Specify the flexible_spec and exclusions as follows

NameTypeDescription

flexible_spec

JSON Object

Array of arrays, each of which contains a targeting segment in its appropriate format e.g. interests, behaviors, partner categories and demographics. The top level array has a limit of 25 and secondary level array has a limit of 1,000.

exclusions

JSON Object

A JSON object which contains a targeting segment in its appropriate format e.g. interests, behaviors, partner categories and demographics.

The below example creates an audience of people who live in the U.S, aged between 20-24, who are not (single or married) and have not recently moved and (are travelers or like soccer or movies) and are (newlyweds or like music).

Specify targeting as:

targeting=
{'geo_locations':{ 
  'countries': ['US'], 
}, 
'age_min':20, 
'age_max':24, 
'flexible_spec': [ 
  {
    'behaviors':[{'id':6002714895372,'name':'All travelers'},], 
    'interests':[ 
      {'id':6003107902433,'name':'Association football (Soccer)'}, 
      {'id':6003139266461, 'name': 'Movies'},],  
  }, 
  {
    'life_events':[{'id': 6002714398172, 'name': 'Newlywed (1 year)'}],
    'interests':[{'id':6003020834693,'name':'Music'},], 
  },   
], 
'exclusions': { 
  'relationship_statuses':[1,3], 
  'life_events':[{'id':6003054185372,'name':'Recently moved'},], 
}, 
} 

Resulting targeting spec for the ad set:

{
  "targeting": { 
    "age_min": 20, 
    "age_max": 24,
    "exclusions": {
      "life_events": [
        {
          "id": "6003054185372", 
          "name": "Recently moved"
        }
      ], 
      "relationship_statuses": [
        1, 
        3
      ]
    }, 
    "flexible_spec": [
      {
        "interests": [
          {
            "id": "6003107902433", 
            "name": "Association football (Soccer)"
          }, 
          {
            "id": "6003139266461", 
            "name": "Movies"
          }
        ], 
        "behaviors": [
          {
            "id": "6002714895372", 
            "name": "All travelers"
          }
        ]
      }, 
      {
        "interests": [
          {
            "id": "6003020834693", 
            "name": "Music"
          }
        ],       
        "life_events": [
          {
            "id": "6002714398172", 
            "name": "Newlywed (1 year)"
          }
        ]
      }
    ], 
    "geo_locations": {
      "countries": [
        "US"
      ]
    }
  }, 
  "id": "6015417075447"
}

The following fields are supported in flexible targeting:

  • connections
  • friends_of_connections
  • custom_audiences
  • interests
  • user_adclusters
  • behaviors
  • college_years
  • education_majors
  • education_schools
  • education_statuses
  • ethnic_affinity
  • family_statuses
  • generation
  • home_type
  • home_ownership
  • home_value
  • household_composition
  • interested_in
  • income
  • industries
  • life_events
  • moms
  • net_worth
  • office_type
  • politics
  • relationship_statuses
  • work_positions
  • work_employers

Targeting segments e.g. interests/behaviors specified inside flexible_spec are not available for use outside of flexible_spec.

Limits

The following are the limitations on ad targeting

QuestionAnswer

What is the minimum age of a user to whom I can target my ad?

13 years old

What is the maximum age of a user to whom I can target my ad?

65 years old

How many languages can be targeted per ad?

50

How many Interests can I target in the ad create flow?

400

How many colleges can I target in the ad create flow?

200

How many workplaces can I target in the ad create flow?

200

How many majors can I target in the ad create flow?

200

How many cities can I target in the ad create flow?

250

How many connections can I target in the ad create flow?

50

What is the oldest graduation year that I can target?

1980

Examples

Targeting by countries

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Targeting;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My Ad Set',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array('US'),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED,
));
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.targeting import Targeting

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My Ad Set',
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.daily_budget: 1000,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.bid_amount: 2,
    AdSet.Field.targeting: {
        Targeting.Field.geo_locations: {
            'countries': ['US'],
        },
    },
})

adset.remote_create(params={
    'status': AdSet.Status.paused,
})
print(adset)
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My Ad Set")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_PAUSED)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My Ad Set' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={"geo_locations":{"countries":["US"]}}' \
  -F 'status=PAUSED' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting with country exclusion

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array('US'),
    ),
    TargetingFields::EXCLUDED_GEO_LOCATIONS => array(
      'regions' => array(
        array(
          'key' => '3847',
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'excluded_geo_locations': {
            'regions': [
                {'key': 3847},
            ],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldExcludedGeoLocations(
        new TargetingGeoLocation()
          .setFieldRegions(Arrays.asList(
            new TargetingGeoLocationRegion()
              .setFieldKey("3847")
          ))
      )
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "excluded_geo_locations": {"regions":[{"key":"3847"}]}, 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting by zip codes

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      TargetingFields::ZIPS => array(
        array(
          'key' => 'US:94304',
        ),
        array(
          'key' => 'US:00501',
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'zips': [
                {
                    'key': 'US:94304',
                },
                {
                    'key': 'US:00501',
                },
            ],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldZips(Arrays.asList(
            new TargetingGeoLocationZip()
              .setFieldKey("US:94304")
          , 
            new TargetingGeoLocationZip()
              .setFieldKey("US:00501")
          ))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={"geo_locations":{"zips":[{"key":"US:94304"},{"key":"US:00501"}]}}' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting by Custom Locations, DMAs and Location Types

To target 5 miles around 1601 Willow Road, Menlo Park, CA and 5 kilometers around latitude 36 longitude -121.0 and the DMAs 501 and 543 with location type as recent and home

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'custom_locations' => array(
        array(
          'address_string' => '1601 Willow Road, Menlo Park, CA',
          'radius' => '5',
        ),
        array(
          'latitude' => '36',
          'longitude' => '-121.0',
          'radius' => '5',
          'distance_unit' => 'kilometer',
        ),
      ),
      'geo_markets' => array(
        array(
          'key' => 'DMA:501',
          'name' => 'New York',
        ),
        array(
          'key' => 'DMA:543',
          'name' => 'Springfield-Holyoke',
        ),
      ),
      'location_types' => array('recent', 'home'),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'custom_locations': [
                {
                    'address_string': '1601 Willow Road, Menlo Park, CA',
                    'radius': 5,
                },
                {
                    'latitude': 36,
                    'longitude': -121.0,
                    'radius': 5,
                    'distance_unit': 'kilometer',
                },
            ],
            'location_types': ['recent', 'home'],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCustomLocations(Arrays.asList(
            new TargetingGeoLocationCustomLocation()
              .setFieldAddressString("1601 Willow Road, Menlo Park, CA")
              .setFieldRadius((double) 5)
          , 
            new TargetingGeoLocationCustomLocation()
              .setFieldDistanceUnit("kilometer")
              .setFieldLatitude((double) 36)
              .setFieldLongitude((double) -121.0)
              .setFieldRadius((double) 5)
          ))
          .setFieldGeoMarkets(Arrays.asList(
            new TargetingGeoLocationMarket()
              .setFieldKey("DMA:501")
              .setFieldName("New York")
          , 
            new TargetingGeoLocationMarket()
              .setFieldKey("DMA:543")
              .setFieldName("Springfield-Holyoke")
          ))
          .setFieldLocationTypes(Arrays.asList("recent", "home"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": { 
      "custom_locations": [ 
        {"address_string":"1601 Willow Road, Menlo Park, CA","radius":"5"}, 
        { 
          "latitude": "36", 
          "longitude": "-121.0", 
          "radius": "5", 
          "distance_unit": "kilometer" 
        } 
      ], 
      "geo_markets": [ 
        {"key":"DMA:501","name":"New York"}, 
        {"key":"DMA:543","name":"Springfield-Holyoke"} 
      ], 
      "location_types": ["recent","home"] 
    } 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting Mobile Devices

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::USER_DEVICE => array(
      'Galaxy S6',
      'One m9',
    ),
    TargetingFields::USER_OS => array('android'),
  )),
));

$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'user_device': [
            'galaxy s6',
            'one m9',
        ],
        'user_os': ['android'],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldUserDevice(Arrays.asList("Galaxy S6", "One m9"))
      .setFieldUserOs(Arrays.asList("android"))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "user_device": ["Galaxy S6","One m9"], 
    "user_os": ["android"] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Specifying a Placement

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::PUBLISHER_PLATFORMS => array(
      'facebook',
      'audience_network',
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        Targeting.Field.publisher_platforms: ['facebook', 'audience_network'],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldPublisherPlatforms(Arrays.asList("facebook", "audience_network"))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "publisher_platforms": ["facebook","audience_network"] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting by Interests

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::INTERESTS => array(
      array(
        'id' => 6003139266461,
        'name' => 'Movies',
      ),
      array(
        'id' => 6003397425735,
        'name' => 'Tennis',
      ),
      array(
        'id' => 6003659420716,
        'name' => 'Cooking',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'interests': [
            {
                'id': 6003139266461,
                'name': 'Movies',
            },
            {
                'id': 6003397425735,
                'name': 'Tennis',
            },
            {
                'id': 6003659420716,
                'name': 'Cooking',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldInterests(Arrays.asList(
        new IDName()
          .setFieldId("6003139266461")
          .setFieldName("Movies")
      , 
        new IDName()
          .setFieldId("6003397425735")
          .setFieldName("Tennis")
      , 
        new IDName()
          .setFieldId("6003659420716")
          .setFieldName("Cooking")
      ))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "interests": [ 
      {"id":6003139266461,"name":"Movies"}, 
      {"id":6003397425735,"name":"Tennis"}, 
      {"id":6003659420716,"name":"Cooking"} 
    ] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting by Behaviors

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::BEHAVIORS => array(
      array(
        'id' => 6004386044572,
        'name' => 'Android Owners (All)',
      ),
      array(
        'id' => 6007101597783,
        'name' => 'Business Travelers',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'behaviors': [
            {
                'id': 6004386044572,
                'name': 'Android Owners (All)',
            },
            {
                'id': 6007101597783,
                'name': 'Business Travelers',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldBehaviors(Arrays.asList(
        new IDName()
          .setFieldId("6004386044572")
          .setFieldName("Android Owners (All)")
      , 
        new IDName()
          .setFieldId("6007101597783")
          .setFieldName("Business Travelers")
      ))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "behaviors": [ 
      {"id":6004386044572,"name":"Android Owners (All)"}, 
      {"id":6007101597783,"name":"Business Travelers"} 
    ], 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting by Demographic

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::RELATIONSHIP_STATUSES => array(2, 4),
    TargetingFields::LIFE_EVENTS => array(
      array(
        'id' => 6003054185372,
        'name' => 'Recently Moved',
      ),
    ),
    TargetingFields::INDUSTRIES => array(
      array(
        'id' => 6009003307783,
        'name' => 'Accounting and finance',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'relationship_statuses': [2, 4],
        'life_events': [
            {
                'id': 6003054185372,
                'name': 'Recently Moved',
            },
        ],
        'industries': [
            {
                'id': 6009003307783,
                'name': 'Accounting and finance',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldIndustries(Arrays.asList(
        new IDName()
          .setFieldId("6009003307783")
          .setFieldName("Accounting and finance")
      ))
      .setFieldLifeEvents(Arrays.asList(
        new IDName()
          .setFieldId("6003054185372")
          .setFieldName("Recently Moved")
      ))
      .setFieldRelationshipStatuses(Arrays.asList(2L, 4L))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "industries": [{"id":6009003307783,"name":"Accounting and finance"}], 
    "life_events": [{"id":6003054185372,"name":"Recently Moved"}], 
    "relationship_statuses": [2,4] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting by Location, Demographic, Relationship Status & Interests

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'regions' => array(
        array(
          'key' => '3847',
        ),
      ),
      'cities' => array(
        array(
          'key' => '2430536',
          'radius' => 12,
          'distance_unit' => 'mile'
        ),
      ),
    ),
    TargetingFields::GENDERS => array(1,),
    TargetingFields::RELATIONSHIP_STATUSES => array(2, 3, 4,),
    TargetingFields::AGE_MIN => 18,
    TargetingFields::AGE_MAX => 43,
    TargetingFields::INTERESTS => array(
      array(
        'id' => 6003139266461,
        'name' => 'Movies',
      ),
    ),
  )),
));

$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'regions': [{'key': '3847'}],
            'cities': [
                {
                    'key': '2430536',
                    'radius': '12',
                    'distance_unit': 'mile',
                },
            ],
        },
        'genders': [1],
        'relationship_statuses': [2, 3, 4],
        'age_min': 18,
        'age_max': 43,
        'interests': [
            {
                'id': 6003139266461,
                'name': 'Movies',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldAgeMax(43L)
      .setFieldAgeMin(18L)
      .setFieldGenders(Arrays.asList(1L))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCities(Arrays.asList(
            new TargetingGeoLocationCity()
              .setFieldDistanceUnit("mile")
              .setFieldKey("2430536")
              .setFieldRadius(12L)
          ))
          .setFieldRegions(Arrays.asList(
            new TargetingGeoLocationRegion()
              .setFieldKey("3847")
          ))
      )
      .setFieldInterests(Arrays.asList(
        new IDName()
          .setFieldId("6003139266461")
          .setFieldName("Movies")
      ))
      .setFieldRelationshipStatuses(Arrays.asList(2L, 3L, 4L))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "age_max": 43, 
    "age_min": 18, 
    "genders": [1], 
    "geo_locations": { 
      "regions": [{"key":"3847"}], 
      "cities": [ 
        { 
          "key": "2430536", 
          "radius": 12, 
          "distance_unit": "mile" 
        } 
      ] 
    }, 
    "interests": [{"id":6003139266461,"name":"Movies"}], 
    "relationship_statuses": [ 
      2, 
      3, 
      4 
    ] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting using Flexible Targeting

To target people who live in the U.S, aged between 20-24, who are not (single or married) and have not recently moved and (are travelers or like soccer or movies) and are (newlyweds or like music):

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 150,
  AdSetFields::DAILY_BUDGET => 2000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::AGE_MIN => 18,
    TargetingFields::AGE_MAX => 43,
    TargetingFields::FLEXIBLE_SPEC => array(
      array(
        TargetingFields::BEHAVIORS => array(
          array(
            'id' => 6002714895372,
            'name' => 'All travelers',
          ),
        ),
        TargetingFields::INTERESTS => array(
          array(
            'id' => 6003107902433,
            'name' => 'Association football (Soccer)',
          ),
          array(
            'id' => 6003139266461,
            'name' => 'Movies',
          ),
        ),
      ),
      array(
        TargetingFields::INTERESTS => array(
          array(
            'id' => 6003020834693,
            'name' => 'Music',
          ),
        ),
        TargetingFields::LIFE_EVENTS => array(
          array(
            'id' => 6002714398172,
            'name' => 'Newlywed (1 year)',
          ),
        ),
      ),
    ),
    TargetingFields::EXCLUSIONS => array(
      TargetingFields::RELATIONSHIP_STATUSES => array(1, 3),
      TargetingFields::LIFE_EVENTS => array(
        array(
          'id' => 6003054185372,
          'name' => 'Recently moved',
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'age_min': 18,
        'age_max': 43,
        'flexible_spec': [
            {
                'behaviors': [
                    {
                        'id': 6002714895372,
                        'name': 'All travelers',
                    },
                ],
                'interests': [
                    {
                        'id': 6003107902433,
                        'name': 'Association football (Soccer)',
                    },
                    {
                        'id': 6003139266461,
                        'name': 'Movies',
                    },
                ],
            },
            {
                'interests': [
                    {
                        'id': 6003020834693,
                        'name': 'Music',
                    },
                ],
                'life_events': [
                    {
                        'id': 6002714398172,
                        'name': 'Newlywed (1 year)',
                    },
                ],
            },
        ],
        'exclusions': {
            'relationship_statuses': [1, 3],
            'life_events': [
                {
                    'id': 6003054185372,
                    'name': 'Recently moved',
                },
            ],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(150L)
  .setDailyBudget(2000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldAgeMax(43L)
      .setFieldAgeMin(18L)
      .setFieldExclusions(
        new FlexibleTargeting()
          .setFieldLifeEvents(Arrays.asList(
            new IDName()
              .setFieldId("6003054185372")
              .setFieldName("Recently moved")
          ))
          .setFieldRelationshipStatuses(Arrays.asList(1L, 3L))
      )
      .setFieldFlexibleSpec(Arrays.asList(
        new FlexibleTargeting()
          .setFieldBehaviors(Arrays.asList(
            new IDName()
              .setFieldId("6002714895372")
              .setFieldName("All travelers")
          ))
          .setFieldInterests(Arrays.asList(
            new IDName()
              .setFieldId("6003107902433")
              .setFieldName("Association football (Soccer)")
          , 
            new IDName()
              .setFieldId("6003139266461")
              .setFieldName("Movies")
          ))
      , 
        new FlexibleTargeting()
          .setFieldInterests(Arrays.asList(
            new IDName()
              .setFieldId("6003020834693")
              .setFieldName("Music")
          ))
          .setFieldLifeEvents(Arrays.asList(
            new IDName()
              .setFieldId("6002714398172")
              .setFieldName("Newlywed (1 year)")
          ))
      ))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=150' \
  -F 'daily_budget=2000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "age_max": 43, 
    "age_min": 18, 
    "exclusions": { 
      "relationship_statuses": [1,3], 
      "life_events": [{"id":6003054185372,"name":"Recently moved"}] 
    }, 
    "flexible_spec": [ 
      { 
        "behaviors": [{"id":6002714895372,"name":"All travelers"}], 
        "interests": [ 
          {"id":6003107902433,"name":"Association football (Soccer)"}, 
          {"id":6003139266461,"name":"Movies"} 
        ] 
      }, 
      { 
        "interests": [{"id":6003020834693,"name":"Music"}], 
        "life_events": [{"id":6002714398172,"name":"Newlywed (1 year)"}] 
      } 
    ], 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting Broad Category Targeting (BCT)

To include the cooking category and small business owner category:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::USER_ADCLUSTERS => array(
      array(
        'id' => 6002714885172,
        'name' => 'Cooking',
      ),
      array(
        'id' => 6002714898572,
        'name' => 'Small Business Owners',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'user_adclusters': [
            {
                'id': 6002714885172,
                'name': 'Cooking',
            },
            {
                'id': 6002714898572,
                'name': 'Small Business Owners',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldUserAdclusters(Arrays.asList(
        new IDName()
          .setFieldId("6002714885172")
          .setFieldName("Cooking")
      , 
        new IDName()
          .setFieldId("6002714898572")
          .setFieldName("Small Business Owners")
      ))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "user_adclusters": [ 
      {"id":6002714885172,"name":"Cooking"}, 
      {"id":6002714898572,"name":"Small Business Owners"} 
    ] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting Broad Category Targeting (BCT) Exclusion

To exclude the cooking category and small business owner category:

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::EXCLUSIONS => array(
      TargetingFields::USER_ADCLUSTERS => array(
        array(
         'id' => 6002714885172,
         'name' => 'Cooking',
        ),
        array(
         'id' => 6002714898572,
         'name' => 'Small Business Owners',
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'exclusions': {
            'user_adclusters': [
                {
                    'id': 6002714885172,
                    'name': 'Cooking',
                },
                {
                    'id': 6002714898572,
                    'name': 'Small Business Owners',
                },
            ],
        },
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldExclusions(
        new FlexibleTargeting()
          .setFieldUserAdclusters(Arrays.asList(
            new IDName()
              .setFieldId("6002714885172")
              .setFieldName("Cooking")
          , 
            new IDName()
              .setFieldId("6002714898572")
              .setFieldName("Small Business Owners")
          ))
      )
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "exclusions": { 
      "user_adclusters": [ 
        {"id":6002714885172,"name":"Cooking"}, 
        {"id":6002714898572,"name":"Small Business Owners"} 
      ] 
    }, 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting BCT & Location & Demographics

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::RELATIONSHIP_STATUSES => array (2),
    TargetingFields::USER_ADCLUSTERS => array(
      array(
        'id' => 6002714886772,
        'name' => 'Food & Dining',
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'relationship_statuses': [2],
        'user_adclusters': [
            {
                'id': 6002714886772,
                'name': 'Food & Dining',
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
      .setFieldRelationshipStatuses(Arrays.asList(2L))
      .setFieldUserAdclusters(Arrays.asList(
        new IDName()
          .setFieldId("6002714886772")
          .setFieldName("Food & Dining")
      ))
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "geo_locations": {"countries":["US"]}, 
    "relationship_statuses": [2], 
    "user_adclusters": [{"id":6002714886772,"name":"Food & Dining"}] 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting Partner Categories

To target people who are recent home buyers and in household size bigger than 3.

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::FLEXIBLE_SPEC => array(
      array(
        TargetingFields::USER_ADCLUSTERS => array(
          array(
            'id' => 6006371340132,
            'name' => 'Demographic > Household Size > 3',
          ),
        ),
      ),
      array(
        TargetingFields::USER_ADCLUSTERS => array(
          array(
            'id' => 6006371326532,
            'name' => 'Demographic > Home > Home Owner > Recent Buyer',
          ),
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'flexible_spec': [
            {
                'user_adclusters': [
                    {
                        'id': 6006371340132,
                        'name': 'Demographic > Household Size > 3',
                    },
                ],
            },
            {
                'user_adclusters': [
                    {
                        'id': 6006371326532,
                        'name': 'Demographic > Home > Home Owner > Recent Buyer'
                    },
                ],
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldFlexibleSpec(Arrays.asList(
        new FlexibleTargeting()
          .setFieldUserAdclusters(Arrays.asList(
            new IDName()
              .setFieldId("6006371340132")
              .setFieldName("Demographic > Household Size > 3")
          ))
      , 
        new FlexibleTargeting()
          .setFieldUserAdclusters(Arrays.asList(
            new IDName()
              .setFieldId("6006371326532")
              .setFieldName("Demographic > Home > Home Owner > Recent Buyer")
          ))
      ))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "flexible_spec": [ 
      { 
        "user_adclusters": [{"id":6006371340132,"name":"Demographic > Household Size > 3"}] 
      }, 
      { 
        "user_adclusters": [ 
          { 
            "id": 6006371326532, 
            "name": "Demographic > Home > Home Owner > Recent Buyer" 
          } 
        ] 
      } 
    ], 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting BCT & Partner Categories

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
    TargetingFields::FLEXIBLE_SPEC => array(
      array(
        TargetingFields::USER_ADCLUSTERS => array(
          array(
           'id' => 6002714885172,
            'name' => 'Cooking',
          ),
        ),
      ),
      array(
        TargetingFields::USER_ADCLUSTERS => array(
          array(
            'id' => 6006371326532,
            'name' => 'Demographic > Home > Home Owner > Recent Buyer',
          ),
        ),
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'flexible_spec': [
            {
                'user_adclusters': [
                    {
                        'id': 6002714885172,
                        'name': 'Cooking',
                    },
                ],
            },
            {
                'user_adclusters': [
                    {
                        'id': 6006371326532,
                        'name': 'Demographic > Home > Home Owner > Recent Buyer'
                    },
                ],
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldFlexibleSpec(Arrays.asList(
        new FlexibleTargeting()
          .setFieldUserAdclusters(Arrays.asList(
            new IDName()
              .setFieldId("6002714885172")
              .setFieldName("Cooking")
          ))
      , 
        new FlexibleTargeting()
          .setFieldUserAdclusters(Arrays.asList(
            new IDName()
              .setFieldId("6006371326532")
              .setFieldName("Demographic > Home > Home Owner > Recent Buyer")
          ))
      ))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "flexible_spec": [ 
      {"user_adclusters":[{"id":6002714885172,"name":"Cooking"}]}, 
      { 
        "user_adclusters": [ 
          { 
            "id": 6006371326532, 
            "name": "Demographic > Home > Home Owner > Recent Buyer" 
          } 
        ] 
      } 
    ], 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets

Targeting Custom Audience & Partner Categories

To target your audience who either have bought games from you directly or are in the "Gamers" partner category.

use FacebookAds\Object\AdSet;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\Values\AdSetBillingEventValues;
use FacebookAds\Object\Values\AdSetOptimizationGoalValues;
use FacebookAds\Object\Fields\TargetingFields;
use FacebookAds\Object\Targeting;

$adset = new AdSet(null, 'act_<AD_ACCOUNT_ID>');
$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::OPTIMIZATION_GOAL => AdSetOptimizationGoalValues::REACH,
  AdSetFields::BILLING_EVENT => AdSetBillingEventValues::IMPRESSIONS,
  AdSetFields::BID_AMOUNT => 2,
  AdSetFields::DAILY_BUDGET => 1000,
  AdSetFields::CAMPAIGN_ID => <CAMPAIGN_ID>,
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array('US'),
    ),
    TargetingFields::CUSTOM_AUDIENCES => array(
      array(
        'id' => <AUDIENCE_ID>,
        'name' => <AUDIENCE_NAME>,
      ),
    ),
  )),
));
$adset->create(array(
  AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE,
));
from facebookads.adobjects.adset import AdSet

adset = AdSet(parent_id='act_<AD_ACCOUNT_ID>')
adset.update({
    AdSet.Field.name: 'My AdSet',
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
    AdSet.Field.bid_amount: 150,
    AdSet.Field.daily_budget: 2000,
    AdSet.Field.campaign_id: <CAMPAIGN_ID>,
    AdSet.Field.targeting: {
        'geo_locations': {
            'countries': ['US'],
        },
        'custom_audiences': [
            {
                'id': <CUSTOM_AUDIENCE_ID>,
                'name': <AUDIENCE_NAME>,
            },
        ],
    },
})
adset.remote_create(params={
    'status': AdSet.Status.active,
})
AdSet adSet = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAdSet()
  .setName("My AdSet")
  .setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_REACH)
  .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
  .setBidAmount(2L)
  .setDailyBudget(1000L)
  .setCampaignId(<CAMPAIGN_ID>)
  .setTargeting(
    new Targeting()
      .setFieldCustomAudiences(Arrays.asList(
        new IDName()
          .setFieldId(<AUDIENCE_ID>)
          .setFieldName(<AUDIENCE_NAME>)
      ))
      .setFieldGeoLocations(
        new TargetingGeoLocation()
          .setFieldCountries(Arrays.asList("US"))
      )
  )
  .setStatus(AdSet.EnumStatus.VALUE_ACTIVE)
  .execute();
String ad_set_id = adSet.getId();
curl \
  -F 'name=My AdSet' \
  -F 'optimization_goal=REACH' \
  -F 'billing_event=IMPRESSIONS' \
  -F 'bid_amount=2' \
  -F 'daily_budget=1000' \
  -F 'campaign_id=<CAMPAIGN_ID>' \
  -F 'targeting={ 
    "custom_audiences": [{"id":"<AUDIENCE_ID>","name":"<AUDIENCE_NAME>"}], 
    "geo_locations": {"countries":["US"]} 
  }' \
  -F 'status=ACTIVE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/adsets