def enable_an_on_adsets(self, adsetids): """ Method that takes a list of ad set ids and enables the audience network placement on them. Please note that this method does not perform any pre-validation check to see whether the ad set passed satisfies the pre-requisites to have audience network enabled. Args: adsetids: List of ad set ids on which you want audience network enabled. Even if you have just one id, pass it as a list. Returns: A list of 'ad set id' vs. 'status' mapping with a further 'message' node whenever there was a failure to update the audience network. Returns an empty list when an empty list or non list element is passed. status 1 is a success. status 0 is a failure. Sample response format: [ {'<ad_set_id_1>': {'status': 1}}, {'<ad_set_id_2>': {'status': 0, 'message': '<exception_msg>'}}, ... ] """ results = [] # check if adsets is a list if type(adsetids) is not list: return results # go over the list of adset ids for adsetid in adsetids: try: # read ad set info adset = AdSet(fbid=adsetid) adsetobj = adset.remote_read(fields=[AdSet.Field.targeting]) # edit targeting spec info for placements targetinginfo = copy.deepcopy(adsetobj[AdSet.Field.targeting]) targetinginfo[Targeting.Field.publisher_platforms]. \ append('audience_network') # update ad set info adset.update({AdSet.Field.targeting: targetinginfo}) adset.remote_update() # update result list along with status results.append({adsetid: {'status': 1}}) except FacebookError as e: # update result list along with status & message results.append({adsetid: {'status': 0, 'message': e.message}}) return results
def update_adset(request, adsetid, status): FacebookAdsApi.init(access_token=access_token, app_id=app_id, app_secret=app_secret) adset = AdSet(adsetid) adset[AdSet.Field.status] = status adset.remote_update() return redirect('view-adset')
def adset_status_update(self, adset_id): try: adset = AdSet(fbid=adset_id) adset.update({ AdSet.Field.status: AdSet.Status.active, }) adset.remote_update() print("Successfully AdSet updated!") except Exception as e: print(e)
def update_interest(adset_id=None, adset_params=None): adset = AdSet(adset_id) update_response = adset.update(adset_params) remote_update_response = adset.remote_update(params={ 'status': 'PAUSED', }) return