def get_adsets(self): adset_list = list() campaign = Campaign(self.campaign_id) adsets = campaign.get_ad_sets(fields=[AdSet.Field.id]) ads = campaign.get_ad_sets(fields=[AdSet.Field.id]) for adset in adsets: adset_list.append(adset.get("id")) return adset_list
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]))
from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.campaign import Campaign import sys from env import ACCESS_TOKEN, CAMPAIGN_ID FacebookAdsApi.init(access_token=ACCESS_TOKEN) campaign = Campaign(fbid=CAMPAIGN_ID) ad_sets = campaign.get_ad_sets(fields=['name']) since = sys.argv[1] if len(sys.argv) > 1 else '2017-05-10' until = sys.argv[2] if len(sys.argv) > 2 else '2019-04-18' metric = sys.argv[3] if len(sys.argv) > 3 else 'link_click' def find_cost_per_action_type(action_type, list): for entry in list: if metric == entry['action_type']: return float(entry['value']) return None def get_insights(ad_set, action_type): insight_list = ad_set.get_insights( fields=['cost_per_action_type'], params={'time_range': { 'since': since,
] 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) print(video.get_thumbnails(fields=[], params={})) video = video.api_get(fields=[AdVideo.Field.id, AdVideo.Field.title]) vname = video[AdVideo.Field.title] print(vid) print(vname) # duplicate adset asr = adsett.create_copy(params={'deep_copy': True})
'effective_status': ['ACTIVE'], 'filtering': [{'field':'name', 'operator':'CONTAIN','value':'Weather API'}], #set to SUMMER }) for i in campaigns: c_value = campaigns temp_campaign = Campaign(i["id"]) campaign_name = i["name"] print(temp_campaign, " campaing id") temp_campaign_str = i["id"] adsets = temp_campaign.get_ad_sets(fields=[ AdSet.Field.name, AdSet.Field.id, AdSet.Field.targeting, AdSet.Field.daily_budget, AdSet.Field.bid_adjustments, ]) for iAdSet in adsets: print("act_" + cu_data['cid']) print(iAdSet["daily_budget"]) print(iAdSet["name"].encode('utf-8').strip()) print(iAdSet["targeting"]["geo_locations"]["cities"][0]["name"], "sted") temp_city = iAdSet["targeting"]["geo_locations"]["cities"][0]["name"] if "\xf8" in temp_city.encode('utf-8'): print("found special char") else: