fields_enum is not defined in AdAccount.get_insights(), get_insights_async()
In AdAccount.get_insights() and AdAccount.get_insights_async(), param_types includes the item { 'fields': 'list<fields_enum>' }. This indicates that this method should take the param fields which is a list of fields_enum. However, fields_enum is not defined in the enums var, which results in the following warning:
facebookads/utils/api_utils.py:30: UserWarning: value of fields might not be compatible. Expect list<fields_enum>; got <type 'list'>
warnings.warn(message)
enums needs to include { 'fields_enum': AdsInsights.Fields.__dict__.values() } so that this is avoided.
Any plan when it will be fixed?
You can't use try/catch because these are warnings that come from the API library.
I ended up overriding the following two classes to get rid of the warnings:
-- do this first: class AdsInsights() --> eg. class FBAdsInsights(AdsInsights) enum definition overriden: FBAdsInsights.Fields
-- then you can use FBAdsInsights instances... class AdAccount() --> eg. class FBAdAccount(AdAccount) Methods overrriden: FBAdAccount.get_insights() FBAdAccount.get_insights_async() added: 'fields_enum': FBAdsInsights.Fields.dict.values(),
Works fine with fb API v.2.8
@jmandrake can you do a pull request for this, this warnings are really filling up my logs ...
` import warnings warnings.filterwarnings('ignore')
from facebookads.api import FacebookAdsApi from facebookads import objects from facebookads.adobjects.adsinsights import AdsInsights from facebookads.adobjects.abstractobject import AbstractObject from facebookads.adobjects.abstractcrudobject import AbstractCrudObject from facebookads.adobjects.objectparser import ObjectParser from facebookads.api import FacebookRequest from facebookads.typechecker import TypeChecker from facebookads.adobjects.helpers.adaccountmixin import AdAccountMixin from facebookads.mixins import HasAdLabels
from facebookads.adobjects.user import User from facebookads.adobjects.adaccount import AdAccount from facebookads.adobjects.campaign import Campaign from facebookads.adobjects.adset import AdSet from facebookads.adobjects.ad import Ad
class FBAdsInsights(AdsInsights): class Fields: account_id = 'account_id' account_name = 'account_name' action_values = 'action_values' actions = 'actions' ad_id = 'ad_id' ad_name = 'ad_name' adset_id = 'adset_id' adset_name = 'adset_name' app_store_clicks = 'app_store_clicks' buying_type = 'buying_type' call_to_action_clicks = 'call_to_action_clicks' campaign_id = 'campaign_id' campaign_name = 'campaign_name' canvas_avg_view_percent = 'canvas_avg_view_percent' canvas_avg_view_time = 'canvas_avg_view_time' clicks = 'clicks' cost_per_10_sec_video_view = 'cost_per_10_sec_video_view' cost_per_action_type = 'cost_per_action_type' cost_per_estimated_ad_recallers = 'cost_per_estimated_ad_recallers' cost_per_inline_link_click = 'cost_per_inline_link_click' cost_per_inline_post_engagement = 'cost_per_inline_post_engagement' cost_per_total_action = 'cost_per_total_action' cost_per_unique_action_type = 'cost_per_unique_action_type' cost_per_unique_click = 'cost_per_unique_click' cost_per_unique_inline_link_click = 'cost_per_unique_inline_link_click' cpc = 'cpc' cpm = 'cpm' cpp = 'cpp' ctr = 'ctr' date_start = 'date_start' date_stop = 'date_stop' deeplink_clicks = 'deeplink_clicks' estimated_ad_recall_rate = 'estimated_ad_recall_rate' estimated_ad_recallers = 'estimated_ad_recallers' frequency = 'frequency' impressions = 'impressions' inline_link_click_ctr = 'inline_link_click_ctr' inline_link_clicks = 'inline_link_clicks' inline_post_engagement = 'inline_post_engagement' newsfeed_avg_position = 'newsfeed_avg_position' newsfeed_clicks = 'newsfeed_clicks' newsfeed_impressions = 'newsfeed_impressions' objective = 'objective' place_page_name = 'place_page_name' reach = 'reach' relevance_score = 'relevance_score' social_clicks = 'social_clicks' social_impressions = 'social_impressions' social_reach = 'social_reach' social_spend = 'social_spend' spend = 'spend' total_action_value = 'total_action_value' total_actions = 'total_actions' total_unique_actions = 'total_unique_actions' unique_actions = 'unique_actions' unique_clicks = 'unique_clicks' unique_ctr = 'unique_ctr' unique_impressions = 'unique_impressions' unique_inline_link_click_ctr = 'unique_inline_link_click_ctr' unique_inline_link_clicks = 'unique_inline_link_clicks' unique_link_clicks_ctr = 'unique_link_clicks_ctr' unique_social_clicks = 'unique_social_clicks' unique_social_impressions = 'unique_social_impressions' video_10_sec_watched_actions = 'video_10_sec_watched_actions' video_15_sec_watched_actions = 'video_15_sec_watched_actions' video_30_sec_watched_actions = 'video_30_sec_watched_actions' video_avg_pct_watched_actions = 'video_avg_pct_watched_actions' video_avg_percent_watched_actions = 'video_avg_percent_watched_actions' video_avg_sec_watched_actions = 'video_avg_sec_watched_actions' video_avg_time_watched_actions = 'video_avg_time_watched_actions' video_complete_watched_actions = 'video_complete_watched_actions' video_p100_watched_actions = 'video_p100_watched_actions' video_p25_watched_actions = 'video_p25_watched_actions' video_p50_watched_actions = 'video_p50_watched_actions' video_p75_watched_actions = 'video_p75_watched_actions' video_p95_watched_actions = 'video_p95_watched_actions' website_clicks = 'website_clicks' website_ctr = 'website_ctr' `
override AdAccount class \facebookads\adobjects\adaccount.py
` class FBAdAccount(AdAccount):
def get_insights(self, fields=None, params=None, async=False, batch=None, pending=False):
###from facebookads.adobjects.adsinsights import AdsInsights
if async:
return self.get_insights_async(fields, params, batch, pending)
param_types = {
'action_attribution_windows': 'list<action_attribution_windows_enum>',
'action_breakdowns': 'list<action_breakdowns_enum>',
'action_report_time': 'action_report_time_enum',
'breakdowns': 'list<breakdowns_enum>',
'date_preset': 'date_preset_enum',
'default_summary': 'bool',
'export_columns': 'list<string>',
'export_format': 'string',
'export_name': 'string',
'fields': 'list<fields_enum>',
'filtering': 'list<Object>',
'level': 'level_enum',
'product_id_limit': 'int',
'sort': 'list<string>',
'summary': 'list<summary_enum>',
'summary_action_breakdowns': 'list<summary_action_breakdowns_enum>',
'time_increment': 'string',
'time_range': 'Object',
'time_ranges': 'list<Object>',
}
enums = {
'action_attribution_windows_enum': FBAdsInsights.ActionAttributionWindows.__dict__.values(),
'action_breakdowns_enum': FBAdsInsights.ActionBreakdowns.__dict__.values(),
'action_report_time_enum': FBAdsInsights.ActionReportTime.__dict__.values(),
'breakdowns_enum': FBAdsInsights.Breakdowns.__dict__.values(),
'date_preset_enum': FBAdsInsights.DatePreset.__dict__.values(),
### added definition for missing enum type: fields_enum
'fields_enum': FBAdsInsights.Fields.__dict__.values(),
'summary_enum': FBAdsInsights.Summary.__dict__.values(),
'level_enum': FBAdsInsights.Level.__dict__.values(),
'summary_action_breakdowns_enum': FBAdsInsights.SummaryActionBreakdowns.__dict__.values(),
}
request = FacebookRequest(
node_id=self['id'],
method='GET',
endpoint='/insights',
api=self._api,
param_checker=TypeChecker(param_types, enums),
target_class=AdsInsights,
api_type='EDGE',
response_parser=ObjectParser(target_class=AdsInsights),
include_summary=False,
)
request.add_params(params)
request.add_fields(fields)
if batch is not None:
request.add_to_batch(batch)
return request
elif pending:
return request
else:
self.assure_call()
return request.execute()
def get_insights_async(self, fields=None, params=None, batch=None, pending=False):
from facebookads.adobjects.adreportrun import AdReportRun
####from facebookads.adobjects.adsinsights import AdsInsights
param_types = {
'action_attribution_windows': 'list<action_attribution_windows_enum>',
'action_breakdowns': 'list<action_breakdowns_enum>',
'action_report_time': 'action_report_time_enum',
'breakdowns': 'list<breakdowns_enum>',
'date_preset': 'date_preset_enum',
'default_summary': 'bool',
'export_columns': 'list<string>',
'export_format': 'string',
'export_name': 'string',
'fields': 'list<fields_enum>',
'filtering': 'list<Object>',
'level': 'level_enum',
'product_id_limit': 'int',
'sort': 'list<string>',
'summary': 'list<summary_enum>',
'summary_action_breakdowns': 'list<summary_action_breakdowns_enum>',
'time_increment': 'string',
'time_range': 'Object',
'time_ranges': 'list<Object>',
}
enums = {
'action_attribution_windows_enum': FBAdsInsights.ActionAttributionWindows.__dict__.values(),
'action_breakdowns_enum': FBAdsInsights.ActionBreakdowns.__dict__.values(),
'action_report_time_enum': FBAdsInsights.ActionReportTime.__dict__.values(),
'breakdowns_enum': FBAdsInsights.Breakdowns.__dict__.values(),
'date_preset_enum': FBAdsInsights.DatePreset.__dict__.values(),
### added definition for missing enum type: fields_enum
'fields_enum': FBAdsInsights.Fields.__dict__.values(),
'summary_enum': FBAdsInsights.Summary.__dict__.values(),
'level_enum': FBAdsInsights.Level.__dict__.values(),
'summary_action_breakdowns_enum': FBAdsInsights.SummaryActionBreakdowns.__dict__.values(),
}
request = FacebookRequest(
node_id=self['id'],
method='POST',
endpoint='/insights',
api=self._api,
param_checker=TypeChecker(param_types, enums),
target_class=AdReportRun,
api_type='EDGE',
response_parser=ObjectParser(target_class=AdReportRun),
include_summary=False,
)
request.add_params(params)
request.add_fields(fields)
if batch is not None:
request.add_to_batch(batch)
return request
elif pending:
return request
else:
self.assure_call()
return request.execute()
`
Usage: my_account = FBAdAccount(fb_act_id) ... async_job = my_account.get_insights(params=params, async=True) ...
API version used: facebookads==2.8.1
Upgrading to the latest API version: sudo pip install facebookads --upgrade
Notes: 2016-12-08 -- jm Had to replace references to deprecated facebookads.objects with these: from facebookads.adobjects.user import User from facebookads.adobjects.adaccount import AdAccount from facebookads.adobjects.campaign import Campaign from facebookads.adobjects.adset import AdSet from facebookads.adobjects.ad import Ad
Note:
- AdUser object is now User
- AdAccount method get_campaigns() ommitted the params which threw errors with the end point.
Is this going to be fixed? it's opened for around a year now
Please fix. My logs are constantly getting filled with these warnings
It seems like this issue has been open for more than a few months now. We have made many changes in the SDK since then, including releasing a new version. If you can repro your specific issue with the latest version of the SDK, please create a new issue or comment here with further details.