Custom audiences

Note

Before using the Custom Audiences API you must accept the Terms of Service.

Creating a custom audience

fbads.customaudience.add(name, description=None, opt_out_link=None)

Add a new custom audience to the ad account

Parameters:
  • name (str) – Custom audience name
  • description (str) – Custom audience description
  • opt_out_link (str) – Custom audience description
Return type:

A custom audience ID (long)

Exemplo:

from fbads import FBAds

api = FBAds(
    account_id='1233',
    access_token='token_with_ads_permission',
)

custom_audience_id = api.customaudience.add(
    name=u'Test custom audience',
    description='My custom audience',
)

print u'Custom audience created with ID {0}'.format(custom_audience_id)

Adding users

fbads.customaudience.add_users(customaudience_id, facebook_ids=[], emails=[])

You can add users using facebook_ids or e-mails. fbads will hash the e-mail list using md5.

Parameters:
  • customaudience_id (str) – Custom audience ID
  • facebook_ids (str) – List of Facebook IDs
  • emails (str) – List of emails – do not hash the email list, it will be done automatically
Return type:

True (hopefully!)

Exemplo:

from fbads import FBAds

api = FBAds(
    account_id='1233',
    access_token='token_with_ads_permission',
)

api.customaudience.add_users(
    customaudience_id='12345678987654321',
    emails=[
        'example-01@email.com',
        'example-02@email.com',
        'example-03@email.com',
        # ...
    ],
)

# you cannot use emails and facebook_ids at the same time, so
api.customaudience.add_users(
    customaudience_id='12345678987654321',
    facebook_ids=[
        '12345678987001',
        '12345678987002',
        '12345678987003',
        # ...
    ],
)

Removing a custom audience

fbads.customaudience.delete(customaudience_id)

Removes a custom audience from the ad account

Parameters:customaudience_id (str) – Custom audience ID
Return type:True

Exemplo:

api = FBAds(
    account_id='1233',
    access_token='token_with_ads_permission',
)

api.customaudience.delete('123456787654321')