Exemplo n.º 1
0
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
def create_purchase_audience_data(account_id, pixel_id):
  audience_values = [('MAU',30),('WAU',7),('DAU',1)]
  for value in audience_values:
    audience = CustomAudience(parent_id='act_'+str(account_id))
    audience[CustomAudience.Field.name] = value[0]
    audience[CustomAudience.Field.subtype] = CustomAudience.Subtype.website
    audience[CustomAudience.Field.retention_days] = value[1]
    audience[CustomAudience.Field.rule] = {"and":[{"event":{"eq":"Purchase"}}]}
    audience[CustomAudience.Field.pixel_id] = pixel_id
    audience.remote_create()
Exemplo n.º 3
0
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
    def delete_audience(self, name):
        """ This deletes an audience object.
        
        :params name: str, name of audience
        """
        if name not in [audience['name'] for audience in self.audiences]:
            raise ValueError(
                'Attempted to remove audience. Audience does not exist.')

        for audience in list(self.audiences):
            if audience['name'] == name:
                delete_id = audience['id']

        audience = CustomAudience(delete_id)
        audience.remote_delete()
Exemplo n.º 5
0
def CreateCustomAudience(name, description=None, f=None, datatype='email'):
    audience = CustomAudience(parent_id=my_account.get_id_assured())
    audience.update({CustomAudience.Field.name: name})
    if description:
            audience.update({CustomAudience.Field.description: description})
    audience.remote_create()
    print('Created custom audience id ' + audience[CustomAudience.Field.id])
    if f and datatype:
        LoadCustomAudience(audience, f, datatype)
    def create_audience(self, name, desc=None):
        """ This creates an audience object.
        
        :params name: str, name of audience
        :params desc: str, description of audience
        """
        if name in [audience['name'] for audience in self.audiences]:
            raise ValueError(
                'Attempted to add audience. Audience with same name exists.')

        audience = CustomAudience(parent_id=self._account)
        audience[CustomAudience.Field.subtype] = CustomAudience.Subtype.custom
        audience[CustomAudience.Field.name] = '{}'.format(name)

        if desc:
            audience[CustomAudience.Field.description] = desc
        audience.remote_create()
def CreateCustomAudience(name, description=None, f=None, datatype='email'):
    audience = CustomAudience(parent_id=my_account.get_id_assured())
    audience.update({CustomAudience.Field.name: name})
    if description:
            audience.update({CustomAudience.Field.description: description})
    audience.remote_create()
    print('Created custom audience id ' + audience[CustomAudience.Field.id])
    if f and datatype:
        LoadCustomAudience(audience, f, datatype)
    def _get_audience(self, audience_name):
        """ This retrieves an audience object based on a string name.
        
        :params audience_name: str, name of audience
        """
        for audience in list(self.audiences):
            if audience['name'] == audience_name:
                audience_id = audience['id']

        target = CustomAudience(audience_id)

        return target
    def create_lals(
        self,
        account_id,
        seed_id,
        base_name,
        countries,
        ratios,
    ):
        """
        Function that creates the lookalike audiences
        Params:
        * `account_id` is your Facebook AdAccount id
        * `seed_id` is the source custom audience
        * `base_name` the lookalike audiences will have names in the format of
          `[base_name] [COUNTRY_CODE] [RATIO]`
        * `countries` array of country codes
        * `ratios` array of integers stating the lookalike ratio, from 1 to 10
           currency is USD, dailybudget=1000 says your budget is 1000 USD
        """
        lal_created = []

        for country, ratio in itertools.product(countries, ratios):
            # Create the lookalike audience
            lookalike = CustomAudience(parent_id=account_id)
            lookalike[LookalikeAudience.Field.name] = "{0} {1} {2}".format(
                base_name,
                country,
                ratio,
            )
            lookalike[LookalikeAudience.Field.origin_audience_id] = seed_id
            lookalike[LookalikeAudience.Field.lookalike_spec] = {
                LookalikeAudience.Field.LookalikeSpec.ratio: ratio / 100.0,
                LookalikeAudience.Field.LookalikeSpec.country: country,
            }
            lookalike[CustomAudience.Field.subtype] = \
                CustomAudience.Subtype.lookalike
            lookalike.remote_create()
            lal_created.append(lookalike)
        return lal_created
    def create_tiered_lookalikes(
        self,
        account_id,
        name,
        seed_id,
        tiers,
        country
    ):
        """
        Take a seed custom audiences ID and create tiered lookalike audiences
        """
        tiered_audiences = []
        for tier in range(1, tiers + 1):
            lookalike = CustomAudience(parent_id=account_id)
            lookalike[LookalikeAudience.Field.name] = \
                '{0} LAL {1}'.format(name, tier)
            lookalike[LookalikeAudience.Field.origin_audience_id] = seed_id

            lal_spec = {
                LookalikeAudience.Field.LookalikeSpec.ratio: tier / 100.0,
                LookalikeAudience.Field.LookalikeSpec.country: country,
            }
            if (tier > 1):
                lal_spec[
                    # LookalikeAudience.Field.LookalikeSpec.starting_ratio
                    'starting_ratio'
                ] = (tier - 1) / 100.0

            lookalike[LookalikeAudience.Field.lookalike_spec] = lal_spec
            lookalike[CustomAudience.Field.subtype] = \
                CustomAudience.Subtype.lookalike
            lookalike.remote_create()

            tiered_audiences.append(lookalike)

        return tiered_audiences
Exemplo n.º 11
0
def CreateCustomAudience(ad_account, name, description=None, f=None, datatype='email'):
    audience = CustomAudience(parent_id=ad_account.get_id_assured())
    audience.update({
        CustomAudience.Field.name: name,
        CustomAudience.Field.subtype: CustomAudience.Subtype.custom,
    })

    if description:
        audience.update({CustomAudience.Field.description: description})
    audience.remote_create()
    print('Created custom audience id ' + audience[CustomAudience.Field.id])
    if f and datatype:
        return LoadCustomAudience(audience, f, datatype)
    return "No data was uploaded to audience. Only created custom audience id ' + audience[CustomAudience.Field.id]"
Exemplo n.º 12
0
 def create_audience(
     self,
     accountid,
     app_id,
     name,
     retention_days,
     event,
     period,
     greater_than=None,
     less_than=None,
 ):
     """
     Creates a new custom audience and returns the id. The custom audience
     is created based on the cumulative values of the events (add to cart
     or purchase) during the selected period, provided that app is logging
     the selected app event and passing the right value with them.
     """
     audience = CustomAudience(parent_id=accountid)
     technique = {
         'technique_name': 'absolute',
     }
     if greater_than is not None:
         technique['lower_bound'] = greater_than
     if less_than is not None:
         technique['upper_bound'] = less_than
     rule = {
         '_application': app_id,
         '_eventName': event,
         '_cumulativeRule': {
             'metric': 'amount',
             'period': period,
             'technique': technique,
         },
     }
     audience.update({
         CustomAudience.Field.name: name,
         CustomAudience.Field.subtype: CustomAudience.Subtype.app,
         CustomAudience.Field.retention_days: retention_days,
         CustomAudience.Field.rule: json.dumps(rule),
     })
     audience.remote_create()
     caid = audience[CustomAudience.Field.id]
     return caid
 def tearDown(self):
     super(CustomAudienceTestCase, self).tearDown()
     if hasattr(self, 'caid'):
         ca = CustomAudience(self.caid)
         ca.remote_delete()
# use, copy, modify, and distribute this software in source code or binary
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

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]

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

custom_audience_id = fixtures.create_custom_audience().get_id_assured()

# _DOC oncall [ritu]
# _DOC open [CUSTOM_AUDIENCE_USERS_ADD_MULTIKEY]
# _DOC vars [custom_audience_id:s]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
users = [['FirstName', '*****@*****.**', 'LastName1'],
         ['FirstNameTets', '*****@*****.**', 'LastNameTest']]

schema = ['FN', 'EMAIL', 'LN']
audience.add_users(schema, users, is_raw=True)
# _DOC close [CUSTOM_AUDIENCE_USERS_ADD_MULTIKEY]
Exemplo n.º 16
0
def DeleteCustomAudience(audience_id):
    audience = CustomAudience(audience_id)
    print('Deleting audience id ' + audience[CustomAudience.Field.id])
    return audience.remote_delete()
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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
seed_audience_id = fixtures.create_custom_audience().get_id()

# _DOC open [LOOKALIKE_CREATE]
# _DOC vars [ad_account_id:s, campaign_id:s, seed_audience_id:s]
from facebookads.objects import CustomAudience

lookalike = CustomAudience(parent_id=ad_account_id)
lookalike.update({
    CustomAudience.Field.name: 'My lookalike audience',
    CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike,
    CustomAudience.Field.origin_audience_id: seed_audience_id,
    CustomAudience.Field.lookalike_spec: {
        'type': 'similarity',
        'country': 'US',
    },
})

lookalike.remote_create()
print(lookalike)
# _DOC close [LOOKALIKE_CREATE]

lookalike.remote_delete()
Exemplo n.º 18
0
page_api = FacebookAdsApi(page_session)

graph_video_upload_url = 'https://graph-video.facebook.com/' \
    + FacebookAdsApi.API_VERSION + '/' + str(page_id) + '/videos'
response = page_api.call(
    'POST',
    graph_video_upload_url,
    files={'source': (video_path, 'multipart/form-data')},
)
video_id = response.json()['id']

# _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.name] = 'My new CA'
audience[CustomAudience.Field.description] = 'People who bought on my website'

audience.remote_create()
# _DOC close [CUSTOM_AUDIENCE_CREATE]

custom_audience_id = audience.get_id()

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

audience = CustomAudience(custom_audience_id)
users = ['*****@*****.**', '*****@*****.**', '*****@*****.**']
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

pixel_id = fixtures.create_ads_pixel().get_id()
ad_account_id = test_config.account_id

# _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'
audience[CustomAudience.Field.subtype] = CustomAudience.Subtype.website
audience[CustomAudience.Field.retention_days] = 15
audience[CustomAudience.Field.rule] = {'url': {'i_contains': 'shoes'}}
audience[CustomAudience.Field.pixel_id] = pixel_id

audience.remote_create()
# _DOC close [CUSTOM_AUDIENCE_CREATE_WCA]
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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
pixel_id = fixtures.create_ads_pixel().get_id()

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

lookalike = CustomAudience(parent_id=ad_account_id)
lookalike.update({
    CustomAudience.Field.name: 'My lookalike audience',
    CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike,
    CustomAudience.Field.lookalike_spec: {
        'pixel_ids': [pixel_id],
        'ratio': 0.01,
        'conversion_type': 'offsite',
        'country': 'US',
    },
})

lookalike.remote_create()
print(lookalike)
# _DOC close [LOOKALIKE_CREATE_CONVERSION_DATA]
# least 100 people in your source.
from facebookads import test_config

exit(0)

ad_account_id = test_config.account_id
video_path = test_config.video_path

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]
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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
campaign_id = fixtures.create_campaign().get_id()

# _DOC open [LOOKALIKE_CREATE_CAMPAIGN_CONVERSION]
# _DOC vars [ad_account_id:s, campaign_id:s, seed_audience_id:s]
from facebookads.objects import CustomAudience

lookalike = CustomAudience(parent_id=ad_account_id)
lookalike.update({
    CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike,
    CustomAudience.Field.lookalike_spec: {
        'origin_ids': campaign_id,
        'starting_ratio': 0.03,
        'ratio': 0.05,
        'conversion_type': 'campaign_conversions',
        'country': 'US',
    },
})

lookalike.remote_create()
print(lookalike)
# _DOC close [LOOKALIKE_CREATE_CAMPAIGN_CONVERSION]
Exemplo n.º 23
0
page_api = FacebookAdsApi(page_session)

graph_video_upload_url = 'https://graph-video.facebook.com/' \
    + FacebookAdsApi.API_VERSION + '/' + str(page_id) + '/videos'
response = page_api.call(
    'POST',
    graph_video_upload_url,
    files={'source': (video_path, 'multipart/form-data')},
)
video_id = response.json()['id']

# _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.name] = 'My new CA'
audience[CustomAudience.Field.description] = 'People who bought on my website'

audience.remote_create()
# _DOC close [CUSTOM_AUDIENCE_CREATE]

custom_audience_id = audience.get_id()

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

audience = CustomAudience(custom_audience_id)
users = ['*****@*****.**', '*****@*****.**', '*****@*****.**']
def DeleteCustomAudience(audience_id):
    audience = CustomAudience(audience_id)
    print('Deleting audience id ' + audience[CustomAudience.Field.id])
    return audience.remote_delete()
# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

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]

# You are hereby granted a non-exclusive, worldwide, royalty-free license to
# use, copy, modify, and distribute this software in source code or binary
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

custom_audience_id = fixtures.create_custom_audience().get_id_assured()

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

audience = CustomAudience(custom_audience_id)
audience.remote_delete()
# _DOC close [CUSTOM_AUDIENCE_DELETE]
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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 facebookads import test_config

ad_account_id = test_config.account_id
page_id = test_config.page_id

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

lookalike = CustomAudience(parent_id=ad_account_id)
lookalike.update({
    CustomAudience.Field.name: 'My lookalike audience',
    CustomAudience.Field.subtype: CustomAudience.Subtype.lookalike,
    CustomAudience.Field.lookalike_spec: {
        'ratio': 0.01,
        'country': 'US',
        'page_id': page_id,
        'conversion_type': 'page_like',
    },
})

lookalike.remote_create()
print(lookalike)
# _DOC close [LOOKALIKE_CREATE_PAGE_FAN]
# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

custom_audience_id = fixtures.create_custom_audience().get_id_assured()

# _DOC open [CUSTOM_AUDIENCE_USERS_ADD_EMAILS_HASHED]
# _DOC vars [custom_audience_id]
from facebookads.objects import CustomAudience

audience = CustomAudience(custom_audience_id)
users = [
    "f1904cf1a9d73a55fa5de0ac823c4403ded71afd4c3248d00bdcd0866552bb79",
    "ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976",
    "5ff860bf1190596c7188ab851db691f0f3169c453936e9e1eba2f9a47f7a0018",
]

audience.add_users(CustomAudience.Schema.email_hash, users, None, True)
# _DOC close [CUSTOM_AUDIENCE_USERS_ADD_EMAILS_HASHED]
# 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)
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

custom_audience_id = fixtures.create_custom_audience().get_id_assured()

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

audience = CustomAudience(custom_audience_id)
audience.remote_read(fields=[
    CustomAudience.Field.name,
    CustomAudience.Field.rule
])
# _DOC close [CUSTOM_AUDIENCE_READ_RULE]
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

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 = ['*****@*****.**', '*****@*****.**', '*****@*****.**']

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

# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# 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

custom_audience_id = fixtures.create_custom_audience().get_id_assured()

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

audience = CustomAudience(custom_audience_id)
users = ['*****@*****.**', '*****@*****.**', '*****@*****.**']

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