Ejemplo n.º 1
0
def get_ad_data(ad_account: AdAccount) -> {}:
    """Retrieves the ad data of the ad account as a dictionary

    Args:
        ad_account: An ad account for which to retrieve the ad data

    Returns:
        A dictionary with {ad_id: {'name': 1, 'ad_set_id': 2, 'attributes': {}}} format

    """
    logging.info('get ad data for account {}'.format(ad_account['account_id']))
    ads = ad_account.get_ads(fields=['id', 'name', 'adset_id', 'adlabels'],
                             params={
                                 'limit': 1000,
                                 'status': ['ACTIVE', 'PAUSED', 'ARCHIVED']
                             })
    result = {}

    for ad in ads:
        result[ad['id']] = {
            'name': ad['name'],
            'ad_set_id': ad['adset_id'],
            'attributes': parse_labels(ad.get('adlabels', []))
        }
    return result
# 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

ad_account_id = test_config.account_id
ad_label_id = fixtures.create_adlabel().get_id()

# _DOC oncall [pruno]
# _DOC open [ADACCOUNT_GET_ADGROUPS_FILTERING_ADLABELS]
# _DOC vars [ad_account_id:s, ad_label_id]
from facebookads.objects import AdAccount, Ad

params = {
    'filtering': [
        {
            'field': 'adlabels',
            'operator': 'ANY',
            'value': ['for testing'],
        },
    ],
}

ad_account = AdAccount(ad_account_id)
ads = ad_account.get_ads(fields=[Ad.Field.name], params=params)
# _DOC close [ADACCOUNT_GET_ADGROUPS_FILTERING_ADLABELS]
# 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 facebookads import test_config

ad_account_id = test_config.account_id

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

account = AdAccount(ad_account_id)
params = {
    'effective_status': ['ACTIVE',
                         'ADSET_PAUSED',
                         'CAMPAIGN_PAUSED',
                         'PENDING_REVIEW',
                         'DISAPPROVED',
                         'PREAPPROVED',
                         'PENDING_BILLING_INFO',
                         'ARCHIVED',
                         ]
}
ads = account.get_ads(params=params)
for ad in ads:
    print(ad)
# _DOC close [ADACCOUNT_GET_ADGROUPS_WITH_STATUS]
Ejemplo n.º 4
0
# from facebook_business.api import FacebookAdsApi
# from facebook_business.adobjects.adaccount import AdAccount

# my_app_id = '1696381387180237'
# my_app_secret = '2e8c4e640bd999f94838ab90d904fa79'
# my_access_token = 'EAAYG2ZAH8iM0BAEszmfOaZAQ5qr6FW2JyUe2biPyCq02PUHsZAYrOGS1TFH4W1CV8ZBxqY2ENLSqL0tMWsffSU0FNPU7BJZCVG4A50BNyebI0bulWk3oX3GCDL4ZBKnw38qdt7cjXbqq2ZAg7tMuv3fIzCl7Fqnw6nB2uYemLRoHRzuwEgXycVW9422PMGhX99wVCZBpqA0dsz8x2dsCC58K'
# FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
# my_account = AdAccount('act_642303109628222')
# campaigns = my_account.get_campaigns()
# print(campaigns)

from facebookads.objects import AdAccount, Ad

account_id = 'act_1696381387180237'
ad_account = AdAccount(account_id)
ad_iter = ad_account.get_ads(fields=[Ad.Field.name])
for ad in ad_iter:
    print(ad[Ad.Field.name])