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()
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] 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] 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] custom_audience_id = fixtures.create_custom_audience().get_id_assured()
users = ['*****@*****.**', '*****@*****.**', '*****@*****.**'] audience.remove_users(CustomAudience.Schema.email_hash, users) # _DOC close [CUSTOM_AUDIENCE_USERS_REMOVE_EMAILS] # _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] audience.remote_delete() audience = CustomAudience(parent_id=ad_account_id) audience[CustomAudience.Field.name] = 'My new CA' audience[CustomAudience.Field.description] = 'Docsmith Example CA' audience.remote_create() custom_audience_id = audience.get_id() user_id_1 = 1234 user_id_2 = 12345 # _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]
# 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] lookalike.remote_delete()
def DeleteCustomAudience(audience_id): audience = CustomAudience(audience_id) print('Deleting audience id ' + audience[CustomAudience.Field.id]) return audience.remote_delete()
def tearDown(self): super(CustomAudienceTestCase, self).tearDown() if hasattr(self, 'caid'): ca = CustomAudience(self.caid) ca.remote_delete()
# 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]