from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.page import Page FacebookAdsApi.init(access_token='YOUR_ACCESS_TOKEN') # Define the fields to be retrieved fields = [ Page.Field.id, Page.Field.name, Page.Field.fan_count ] # Create the FacebookRequest object and execute the API call page = Page(fbid='PAGE_ID') response = page.get_api_assured().call('GET', params={'fields': ','.join(fields)}) # Print the retrieved information print(response.json())
from facebook_business.api import FacebookAdsApi from facebook_business.adobjects.adaccount import AdAccount from facebook_business.adobjects.campaign import Campaign FacebookAdsApi.init(access_token='YOUR_ACCESS_TOKEN') # Define the fields to be retrieved account_fields = [ AdAccount.Field.id, AdAccount.Field.name, AdAccount.Field.currency ] campaign_fields = [ Campaign.Field.id, Campaign.Field.name, Campaign.Field.status ] # Create the FacebookRequest objects and execute the API calls account = AdAccount('ACT_ID') account_response = account.get_api_assured().call('GET', params={'fields': ','.join(account_fields)}) campaigns = account.get_campaigns(fields=campaign_fields) campaigns_response = campaigns.remote_read() # Print the retrieved information print(account_response.json()) print(campaigns_response.json())In this example, the add_fields method is used by passing the `fields` argument to the `get_campaigns` method. The response will contain only the fields specified in the `campaign_fields` list. Package library: `facebook_business`