Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_ad_campaign(self, cache, campaign_id):
"""
Get the ad campaign. As some ad sets being analyzed belong to the
same ad campaign, a caching is used to reduce the API calls.
Params:
* `cache` ad campaigns obtained already.
* `campaign_id` the id of the ad campaign to be queried out.
"""
if (cache.get(campaign_id) is None):
campaign = Campaign(fbid=campaign_id)
campaign.remote_read(fields=[
Campaign.Field.name,
Campaign.Field.configured_status,
Campaign.Field.objective,
])
cache[campaign_id] = campaign
return cache.get(campaign_id)
facebook_positions = set(
adset[AdSet.Field.targeting][
TargetingSpecsField.facebook_positions]
)
if ((facebook_positions is None or
'feed' in facebook_positions) and
(device_platforms is None or
'mobile' in device_platforms)):
if (publisher_platforms is None or
'audience_network' in publisher_platforms):
# audience network already enabled, so just pass
continue
else:
campaign = Campaign(adset[AdSet.Field.campaign_id])
campaignfields = [
Campaign.Field.id,
Campaign.Field.name,
Campaign.Field.effective_status,
Campaign.Field.objective,
]
campaign = campaign.remote_read(fields=campaignfields)
if (
campaign[Campaign.Field.objective] in
desired_campaign_objectives
):
eligible_adsets.append(adset)
return eligible_adsets
"""
Get the ad campaign. As some ad sets being analyzed belong to the
same ad campaign, a caching is used to reduce the API calls.
Params:
* `cache` ad campaigns obtained already.
* `campaign_id` the id of the ad campaign to be queried out.
"""
if (cache.get(campaign_id) is None):
campaign = Campaign(fbid=campaign_id)
campaign.remote_read(fields=[
Campaign.Field.name,
Campaign.Field.configured_status,
Campaign.Field.objective,
])
cache[campaign_id] = campaign
return cache.get(campaign_id)
def get_ad_campaign(self, cache, campaign_id):
"""
Get the ad campaign. As some ad sets being analyzed belong to the
same ad campaign, a caching is used to reduce the API calls.
Params:
* `cache` ad campaigns obtained already.
* `campaign_id` the id of the ad campaign to be queried out.
"""
if (cache.get(campaign_id) is None):
campaign = Campaign(fbid=campaign_id)
campaign.remote_read(fields=[
Campaign.Field.name,
Campaign.Field.configured_status,
Campaign.Field.objective,
])
cache[campaign_id] = campaign
return cache.get(campaign_id)
# 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
from facebookads.objects import Campaign
ad_account_id = test_config.account_id
page_id = fixtures.get_page_with_locations_id_assured()
campaign_id = fixtures.create_campaign({
Campaign.Field.objective: Campaign.Objective.local_awareness,
Campaign.Field.promoted_object: {
'page_id': page_id,
},
}).get_id()
ad_place_page_set_id = fixtures.create_ad_place_page_set().get_id()
# _DOC oncall [pruno]
# _DOC open [ADSET_CREATE_DLA]
# _DOC vars [campaign_id, ad_account_id:s, ad_place_page_set_id]
from facebookads.objects import AdSet
adset = AdSet(parent_id=ad_account_id)
adset.update({
AdSet.Field.name: 'Local Awareness Ad Set',
AdSet.Field.promoted_object: {
'place_page_set_id': ad_place_page_set_id,
TargetingSpecsField.facebook_positions]
)
if ((facebook_positions is None or
'feed' in facebook_positions) and
(device_platforms is None or
'mobile' in device_platforms)):
if (publisher_platforms is None or
'audience_network' in publisher_platforms):
# audience network already enabled, so just pass
continue
else:
campaign = Campaign(adset[AdSet.Field.campaign_id])
campaignfields = [
Campaign.Field.id,
Campaign.Field.name,
Campaign.Field.effective_status,
Campaign.Field.objective,
]
campaign = campaign.remote_read(fields=campaignfields)
if (
campaign[Campaign.Field.objective] in
desired_campaign_objectives
):
eligible_adsets.append(adset)
return eligible_adsets