How to use the facebookads.objects.AdAccount function in facebookads

To help you get started, we’ve selected a few facebookads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# _DOC open [ADACCOUNT_GET_CONNECTION_OBJECTS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)
objects = account.get_connection_objects()

for obj in objects:
    print(obj[AdAccount.Field.name])
# _DOC close [ADACCOUNT_GET_CONNECTION_OBJECTS]

# _DOC open [ADACCOUNT_GET_ADCREATIVES]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCreative

ad_account = AdAccount(fbid=ad_account_id)
ad_account.get_ad_creatives(fields=[AdCreative.Field.object_story_id])
# _DOC close [ADACCOUNT_GET_ADCREATIVES]


# _DOC open [ADACCOUNT_GET_ADGROUPS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdGroup

ad_account = AdAccount(ad_account_id)
ad_groups = ad_account.get_ad_groups(fields=[AdGroup.Field.name])
for ad_group in ad_groups:
    print(ad_group[AdGroup.Field.name])
# _DOC close [ADACCOUNT_GET_ADGROUPS]


# _DOC open [ADACCOUNT_GET_ADGROUPS_WITH_STATUS]
github facebook / facebook-python-business-sdk / examples / docs / adspixel.py View on Github external
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)

response = pixel.share_pixel(business_id, destination_account_id)
print(response.body())
# _DOC close [ADSPIXEL_SHARE_ADACCOUNT]

# _DOC open [ADSPIXEL_GET_ADACCOUNTS]
# _DOC vars [business_id:s, pixel_id]
from facebookads.objects import AdsPixel, AdAccount

pixel = AdsPixel(pixel_id)
shared_accounts = pixel.list_ad_accounts(business_id)
for shared_account in shared_accounts:
    print(shared_account[AdAccount.Field.id])
# _DOC close [ADSPIXEL_GET_ADACCOUNTS]

destination_business_id = config.secondary_business_id

# _DOC open [ADSPIXEL_SHARE_BUSINESS]
# _DOC vars [destination_business_id:s, pixel_id, business_id:s]
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)

response = pixel.share_pixel_agencies(business_id, destination_business_id)
print(response.body())
# _DOC close [ADSPIXEL_SHARE_BUSINESS]

# We shared the pixel with another business but iit's not associate with any
# ad account.
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
'since': '2015-03-01',
        'until': '2015-03-31'
    }
}
stats = ad_account.get_insights(params=params)
print(stats)
# _DOC close [ADACCOUNT_GET_INSIGHTS_FILTERING_ADLABEL_NAMES]


ad_label_id = fixtures.create_adlabel().get_id()

# _DOC open [ADACCOUNT_GET_INSIGHTS_FILTERING_ADLABEL]
# _DOC vars [ad_account_id:s, ad_label_id:s]
from facebookads.objects import AdAccount, Insights

ad_account = AdAccount(ad_account_id)
params = {
    'fields': [
        Insights.Field.clicks,
        Insights.Field.cpc,
        Insights.Field.total_actions
    ],
    'level': 'adgroup',
    'filtering': [{
        'field': 'adgroup.adlabel_ids',
        'operator': 'ANY',
        'value': [ad_label_id]
    }],
    'time_range': {
        'since': '2015-03-01',
        'until': '2015-03-31'
    }
github facebook / facebook-python-business-sdk / examples / docs / adset.py View on Github external
AdCampaign.Field.buying_type: AdCampaign.BuyingType.fixed_cpm
}

campaign_group_id = fixtures.create_adcampaign(params).get_id_assured()

# _DOC open [ADSET_CREATE_HOMEPAGE]
# _DOC vars [ad_account_id:s, campaign_group_id]
import time
from facebookads.objects import (
    AdAccount,
    AdSet,
    RateCard,
    TargetingSpecsField
)

ad_account = AdAccount(ad_account_id)
rate_cards = ad_account.get_rate_cards()
country = rate_cards[0][RateCard.Field.country]
rate = rate_cards[0][RateCard.Field.rate]

impressions = 5000
lifetime_budget = str(rate * 5000)
end_date = int(time.time() + 12 * 3600)

ad_set = AdSet(parent_id=ad_account_id)
ad_set.update({
    AdSet.Field.name: 'Adset Homepage Ads',
    AdSet.Field.campaign_group_id: campaign_group_id,
    AdSet.Field.lifetime_budget: lifetime_budget,
    AdSet.Field.lifetime_imps: impressions,
    AdSet.Field.optimization_goal: AdSet.OptimizationGoal.reach,
    AdSet.Field.billing_event: AdSet.BillingEvent.impressions,
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# _DOC open [ADACCOUNT_GET_RATECARDS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

ad_account = AdAccount(ad_account_id)
rate_cards = ad_account.get_rate_cards()
print(rate_cards)
# _DOC close [ADACCOUNT_GET_RATECARDS]


# _DOC open [ADACCOUNT_GET_TARGETING_DESCRIPTION]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, TargetingSpecsField

account = AdAccount(ad_account_id)
params = {
    'targeting_spec': {
        TargetingSpecsField.geo_locations: {
            TargetingSpecsField.countries: ['US', 'JP'],
        },
        TargetingSpecsField.genders: [1],
        TargetingSpecsField.age_min: 20,
        TargetingSpecsField.age_max: 24,
    }
}

targeting_description = account.get_targeting_description(params=params)

# Output the targeting description
for description in targeting_description['targetingsentencelines']:
    print(description['content'])
github facebook / facebook-python-business-sdk / examples / docs / adspixel.py View on Github external
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel

pixel = AdsPixel(parent_id=ad_account_id)
pixel[AdsPixel.Field.name] = 'My new Pixel'

pixel.remote_create()
# _DOC close [ADSPIXEL_CREATE]

pixel_id = pixel.get_id()

# _DOC open [ADSPIXEL_READ_PIXEL_CODE]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdsPixel, AdAccount

account = AdAccount(ad_account_id)
account.get_ads_pixels(fields=[AdsPixel.Field.code])
# _DOC close [ADSPIXEL_READ_PIXEL_CODE]

destination_account_id = config.secondary_account_id
business_id = config.business_id

# _DOC open [ADSPIXEL_SHARE_ADACCOUNT]
# _DOC vars [business_id:s, destination_account_id:s, pixel_id]
from facebookads.objects import AdsPixel

pixel = AdsPixel(pixel_id)

response = pixel.share_pixel(business_id, destination_account_id)
print(response.body())
# _DOC close [ADSPIXEL_SHARE_ADACCOUNT]
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
from facebookads.objects import AdLabel

account = AdAccount(ad_account_id)
adlabels = account.get_ad_labels()

for adlabel in adlabels:
    print(adlabel[AdLabel.Field.name])
# _DOC close [ADACCOUNT_GET_ADLABELS]


# _DOC open [ADACCOUNT_GET_ADGROUPS_BY_LABEL]
# _DOC vars [ad_account_id:s, ad_label_id]
from facebookads.objects import AdAccount
from facebookads.objects import AdLabel

account = AdAccount(ad_account_id)
params = {'ad_label_ids': [ad_label_id], 'operator': 'ALL'}
adlabels = account.get_ad_groups_by_labels([AdGroup.Field.name], params=params)

for adlabel in adlabels:
    print(adlabel[AdLabel.Field.name])
# _DOC close [ADACCOUNT_GET_ADGROUPS_BY_LABEL]
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
targeting_description = account.get_targeting_description(params=params)

# Output the targeting description
for description in targeting_description['targetingsentencelines']:
    print(description['content'])
    for child in description['children']:
        print("\t" + child)
# _DOC close [ADACCOUNT_GET_TARGETING_DESCRIPTION]


# _DOC open [ADACCOUNT_GET_REPORTSTATS_DYNAMIC_PRODUCT_ADS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)

params = {
    'data_columns': [
        'account_name', 'impressions', 'clicks', 'actions', 'product_id'
    ],
    'date_preset': 'last_week',
    'actions_group_by': ['action_type'],
}

stats = account.get_report_stats(params=params)
# _DOC close [ADACCOUNT_GET_REPORTSTATS_DYNAMIC_PRODUCT_ADS]


ad_label_id = fixtures.create_adlabel().get_id()

# _DOC open [ADACCOUNT_GET_ADLABELS]
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# 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 facebookads import test_config
from facebookads.objects import AdLabel
from examples.docs import fixtures

ad_account_id = test_config.account_id

# _DOC open [ADACCOUNT_READ]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)

account.remote_read(fields=[
    AdAccount.Field.name,
    AdAccount.Field.balance
])
print(account[AdAccount.Field.name])
print(account[AdAccount.Field.balance])
# _DOC close [ADACCOUNT_READ]


# _DOC open [ADACCOUNT_READ_TOS_ACCEPTED]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)
account.remote_read(fields=[AdAccount.Field.tos_accepted])
github facebook / facebook-python-business-sdk / examples / docs / adaccount.py View on Github external
# _DOC open [ADACCOUNT_GET_ADUSERS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdUser

account = AdAccount(ad_account_id)
users = account.get_ad_users()
for user in users:
    print(user[AdUser.Field.id])
# _DOC close [ADACCOUNT_GET_ADUSERS]


# _DOC open [ADACCOUNT_GET_CONNECTION_OBJECTS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount

account = AdAccount(ad_account_id)
objects = account.get_connection_objects()

for obj in objects:
    print(obj[AdAccount.Field.name])
# _DOC close [ADACCOUNT_GET_CONNECTION_OBJECTS]

# _DOC open [ADACCOUNT_GET_ADCREATIVES]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCreative

ad_account = AdAccount(fbid=ad_account_id)
ad_account.get_ad_creatives(fields=[AdCreative.Field.object_story_id])
# _DOC close [ADACCOUNT_GET_ADCREATIVES]


# _DOC open [ADACCOUNT_GET_ADGROUPS]