How to use the facebookads.objects.CustomAudience function in facebookads

To help you get started, we’ve selected a few facebookads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / facebook-python-business-sdk / examples / docs / customaudience.py View on Github external
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
users = [user_id_1, user_id_2]
apps = [app_id]
audience.add_users(CustomAudience.Schema.uid, users, apps)
# _DOC close [CUSTOM_AUDIENCE_USERS_ADD_ID]


custom_audience_id = fixtures.create_custom_audience().get_id_assured()

# _DOC open [CUSTOM_AUDIENCE_USERS_REMOVE_EMAILS]
# _DOC vars [custom_audience_id:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
users = ['test1@example.com', 'test2@example.com', 'test3@example.com']

audience.remove_users(CustomAudience.Schema.email_hash, users)
# _DOC close [CUSTOM_AUDIENCE_USERS_REMOVE_EMAILS]


exit(0)

##
# (#2654) Source Audience is Too Small: There aren't enough people in your
# source in the country you chose. Please choose a country that includes at
# least 100 people in your source.

custom_audience_id = fixtures.create_custom_audience().get_id_assured()
video_id = fixtures.upload_video(video_path)['id']
github facebook / facebook-python-business-sdk / examples / docs / customaudience.py View on Github external
exit(0)

##
# (#2654) Source Audience is Too Small: There aren't enough people in your
# source in the country you chose. Please choose a country that includes at
# least 100 people in your source.

custom_audience_id = fixtures.create_custom_audience().get_id_assured()
video_id = fixtures.upload_video(video_path)['id']

# _DOC open [CUSTOM_AUDIENCE_CREATE_VIDEO_VIEWS_RETARGET]
# _DOC vars [ad_account_id:s, video_id]
from facebookads.objects import CustomAudience

lookalike = CustomAudience(parent_id=ad_account_id)
lookalike.update({
    CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike,
    CustomAudience.Field.lookalike_spec: {
        'ratio': 0.01,
        'country': 'US',
        'engagement_specs': [
            {
                'action.type': 'video_view',
                'post': video_id,
            },
        ],
        'conversion_type': 'dynamic_rule',
    },
})

lookalike.remote_create()
github facebook / facebook-python-business-sdk / examples / docs / fixtures.py View on Github external
def create_custom_audience():
    audience = CustomAudience(parent_id=test_config.account_id)
    audience[CustomAudience.Field.subtype] = CustomAudience.Subtype.custom
    audience[CustomAudience.Field.name] = unique_name('Test Audience')
    audience[CustomAudience.Field.description] = 'Created for docsmith example'
    audience.remote_create()

    atexit.register(remote_delete, audience)

    return audience
github facebook / facebook-python-business-sdk / examples / docs / customaudience.py View on Github external
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures
from facebookads import test_config

ad_account_id = test_config.account_id
video_path = test_config.video_path


# _DOC open [CUSTOM_AUDIENCE_CREATE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(parent_id=ad_account_id)
audience[CustomAudience.Field.subtype] = CustomAudience.Subtype.custom
audience[CustomAudience.Field.name] = 'My new CA'
audience[CustomAudience.Field.description] = 'People who bought on my website'

audience.remote_create()
# _DOC close [CUSTOM_AUDIENCE_CREATE]


pixel_id = fixtures.create_ads_pixel().get_id_assured()

# _DOC open [CUSTOM_AUDIENCE_CREATE_WCA]
# _DOC vars [ad_account_id:s, pixel_id]
from facebookads.objects import CustomAudience

audience = CustomAudience(parent_id=ad_account_id)
audience[CustomAudience.Field.name] = 'my audience'
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
account = AdAccount(ad_account_id)
images = account.get_ad_images()
# _DOC close [ADACCOUNT_GET_ADIMAGES]


# _DOC open [ADACCOUNT_GET_CUSTOMAUDIENCES_NAME]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, CustomAudience

ad_account = AdAccount(ad_account_id)
custom_audiences = ad_account.get_custom_audiences(fields=[
    CustomAudience.Field.name
])
for custom_audience in custom_audiences:
    print(custom_audience[CustomAudience.Field.name])
# _DOC close [ADACCOUNT_GET_CUSTOMAUDIENCES_NAME]


# _DOC open [ADACCOUNT_GET_INSIGHTS_VIDEO_VIEWS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, Insights

account = AdAccount(ad_account_id)

params = {
    'action_breakdowns': Insights.ActionBreakdown.action_video_type,
    'date_preset': Insights.Preset.last_30_days,
    'fields': [
        Insights.Field.actions,
        Insights.Field.video_avg_pct_watched_actions,
        Insights.Field.video_complete_watched_actions,
github facebook / facebook-python-business-sdk / examples / docs / customaudience.py View on Github external
audience = CustomAudience(custom_audience_id)
audience.remote_read(fields=[
    CustomAudience.Field.name,
    CustomAudience.Field.rule
])
# _DOC close [CUSTOM_AUDIENCE_READ_RULE]


custom_audience_id = fixtures.create_custom_audience().get_id_assured()

# _DOC open [CUSTOM_AUDIENCE_UPDATE_NAME]
# _DOC vars [custom_audience_id:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
audience[CustomAudience.Field.name] = 'Updated name for CA'
audience.remote_update()
# _DOC close [CUSTOM_AUDIENCE_UPDATE_NAME]


custom_audience_id = fixtures.create_custom_audience().get_id_assured()

# _DOC open [CUSTOM_AUDIENCE_UPDATE_OPTOUT]
# _DOC vars [custom_audience_id:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
audience[CustomAudience.Field.opt_out_link] = 'http://www.yourdomain.com/optout'
audience.remote_update()
# _DOC close [CUSTOM_AUDIENCE_UPDATE_OPTOUT]
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# _DOC open [ADACCOUNT_GET_ADIMAGES]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)
images = account.get_ad_images()
# _DOC close [ADACCOUNT_GET_ADIMAGES]


# _DOC open [ADACCOUNT_GET_CUSTOMAUDIENCES_NAME]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, CustomAudience

ad_account = AdAccount(ad_account_id)
custom_audiences = ad_account.get_custom_audiences(fields=[
    CustomAudience.Field.name
])
for custom_audience in custom_audiences:
    print(custom_audience[CustomAudience.Field.name])
# _DOC close [ADACCOUNT_GET_CUSTOMAUDIENCES_NAME]


# _DOC open [ADACCOUNT_GET_INSIGHTS_VIDEO_VIEWS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, Insights

account = AdAccount(ad_account_id)

params = {
    'action_breakdowns': Insights.ActionBreakdown.action_video_type,
    'date_preset': Insights.Preset.last_30_days,
    'fields': [
github facebook / facebook-python-business-sdk / examples / docs / customaudience.py View on Github external
##
# (#2654) Source Audience is Too Small: There aren't enough people in your
# source in the country you chose. Please choose a country that includes at
# least 100 people in your source.

custom_audience_id = fixtures.create_custom_audience().get_id_assured()
video_id = fixtures.upload_video(video_path)['id']

# _DOC open [CUSTOM_AUDIENCE_CREATE_VIDEO_VIEWS_RETARGET]
# _DOC vars [ad_account_id:s, video_id]
from facebookads.objects import CustomAudience

lookalike = CustomAudience(parent_id=ad_account_id)
lookalike.update({
    CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike,
    CustomAudience.Field.lookalike_spec: {
        'ratio': 0.01,
        'country': 'US',
        'engagement_specs': [
            {
                'action.type': 'video_view',
                'post': video_id,
            },
        ],
        'conversion_type': 'dynamic_rule',
    },
})

lookalike.remote_create()
print(lookalike)
# _DOC close [CUSTOM_AUDIENCE_CREATE_VIDEO_VIEWS_RETARGET]
lookalike.remote_delete()
github facebook / facebook-python-business-sdk / examples / docs / customaudience.py View on Github external
users = ['test1@example.com', 'test2@example.com', 'test3@example.com']

audience.add_users(CustomAudience.Schema.email_hash, users)
# _DOC close [CUSTOM_AUDIENCE_USERS_ADD_EMAILS]


custom_audience_id = fixtures.create_custom_audience().get_id_assured()
user_id_1 = 1234
user_id_2 = 12345
app_id = fixtures.test_config.app_id

# _DOC open [CUSTOM_AUDIENCE_USERS_ADD_ID]
# _DOC vars [custom_audience_id:s, app_id:s, user_id_1:s, user_id_2:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
users = [user_id_1, user_id_2]
apps = [app_id]
audience.add_users(CustomAudience.Schema.uid, users, apps)
# _DOC close [CUSTOM_AUDIENCE_USERS_ADD_ID]


custom_audience_id = fixtures.create_custom_audience().get_id_assured()

# _DOC open [CUSTOM_AUDIENCE_USERS_REMOVE_EMAILS]
# _DOC vars [custom_audience_id:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
users = ['test1@example.com', 'test2@example.com', 'test3@example.com']

audience.remove_users(CustomAudience.Schema.email_hash, users)