def run_query_on_fb_campaign_obj_conf(self, params, ad_object_id): campaign = Campaign(ad_object_id) if self.level == LEVELS_POSSIBLE_VALUES[2]: val_cmp = campaign.api_get(fields=self.desired_fields, params=params) yield val_cmp elif self.level == LEVELS_POSSIBLE_VALUES[1]: for el in chain(*[ self.run_query_on_fb_adset_obj_conf( params, adset.get("id")) for adset in campaign.get_ad_sets() ]): yield el else: raise ClickException("Received level: " + self.level + ". Available levels are " + repr(LEVELS_POSSIBLE_VALUES[1:3]))
fbtoken = os.getenv('FB_GA_TOKEN') fbappkey = os.getenv('FB_GA_APPKEY') job = '999_Test_Job' videos = [ '2926386880739508', '506640253392515', '485759768730516' ] FacebookAdsApi.init('2389713357935376', fbappkey, fbtoken) fbact = AdAccount('act_659750741197329') template = Campaign('23844416049080002') template = template.api_get(fields=[Campaign.Field.name]) cr = template.create_copy(fields=None, params={'deep_copy': True}) c = Campaign(cr._data['copied_campaign_id']) c = c.api_get(fields=[Campaign.Field.id, Campaign.Field.name]) cname = template[Campaign.Field.name] + job c.api_update(params={Campaign.Field.name: cname}) adsets = c.get_ad_sets() adsett = adsets[0] for vid in videos: # ids and names will already be indexed, but for the simplicity of use # getting it here video = AdVideo(vid)