facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.28k stars 631 forks source link

bugfix #554

Closed zachliu closed 1 year ago

zachliu commented 4 years ago

If we send an async request like this

ad = Ad(fbid='f{ad_id}')
async_job = ad.get_insights(
    fields=fields,
    params=params,
    is_async=True
)

Every field in the fields list will be "unacceptable" due to the fact that it doesn't belong to this misplaced AdReportRun class. Only the AdsInsights class has these fields.

Nathaaaalie commented 4 years ago

@zachliu Could you specify which fields can not be accessed?

zachliu commented 4 years ago

@zachliu Could you specify which fields can not be accessed?

you misunderstood me, it's not that they cannot be accessed but they generate a bunch of warning messages like this:

/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: value of date_preset might not be compatible. Expect date_preset_enum; got <class 'str'>
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field account_currency
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field account_name
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field action_values
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field ad_id
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field ad_name
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field adset_id
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field adset_name
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field buying_type
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field campaign_id
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field campaign_name
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field canvas_avg_view_percent
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field canvas_avg_view_time
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field clicks
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_10_sec_video_view
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_action_type
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_estimated_ad_recallers
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_inline_link_click
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_inline_post_engagement
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_outbound_click
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_unique_action_type
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_unique_click
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_unique_inline_link_click
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_unique_outbound_click
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field estimated_ad_recallers
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field frequency
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field impressions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field inline_link_clicks
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field inline_post_engagement
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field objective
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field outbound_clicks
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field place_page_name
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field reach
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field social_spend
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field spend
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field unique_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field unique_clicks
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field unique_inline_link_clicks
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field unique_outbound_clicks
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_10_sec_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_30_sec_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_avg_time_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_p100_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_p25_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_p50_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_p75_watched_actions
/usr/local/lib/python3.6/site-packages/facebook_business/utils/api_utils.py:30: UserWarning: insights does not allow field video_p95_watched_actions
jkruk24 commented 4 years ago

I was using this function in my code, but now it's no longer working. How can I adjust my code to account for this? Below is how the code used to look when it was functioning.

attribution = ['7d_click'] params = { 'date_preset': 'yesterday', 'action_attribution_windows': attribution, 'level': 'campaign', 'time_increment': 'monthly', 'filtering': [{'field': "impressions", "operator": "GREATER_THAN", "value": 1}, {'field': "spend", "operator": "GREATER_THAN", "value": 0}], 'fields': [ 'adset_id', 'campaign_id', 'campaign_name', 'action_values', 'reach', 'frequency', 'spend', 'impressions', 'objective', 'actions'] }

async_job = my_account.get_insights_async(fields=params.get('fields'), params=params)
zachliu commented 4 years ago

I was using this function in my code, but now it's no longer working. How can I adjust my code to account for this? Below is how the code used to look when it was functioning.

attribution = ['7d_click'] params = { 'date_preset': 'yesterday', 'action_attribution_windows': attribution, 'level': 'campaign', 'time_increment': 'monthly', 'filtering': [{'field': "impressions", "operator": "GREATER_THAN", "value": 1}, {'field': "spend", "operator": "GREATER_THAN", "value": 0}], 'fields': [ 'adset_id', 'campaign_id', 'campaign_name', 'action_values', 'reach', 'frequency', 'spend', 'impressions', 'objective', 'actions'] }

async_job = my_account.get_insights_async(fields=params.get('fields'), params=params)

Can you be more specific on no longer working? What error messages did you get?

jkruk24 commented 4 years ago

I was using this function in my code, but now it's no longer working. How can I adjust my code to account for this? Below is how the code used to look when it was functioning. attribution = ['7d_click'] params = { 'date_preset': 'yesterday', 'action_attribution_windows': attribution, 'level': 'campaign', 'time_increment': 'monthly', 'filtering': [{'field': "impressions", "operator": "GREATER_THAN", "value": 1}, {'field': "spend", "operator": "GREATER_THAN", "value": 0}], 'fields': [ 'adset_id', 'campaign_id', 'campaign_name', 'action_values', 'reach', 'frequency', 'spend', 'impressions', 'objective', 'actions'] }

async_job = my_account.get_insights_async(fields=params.get('fields'), params=params)

Can you be more specific on no longer working? What error messages did you get?

Fair point, sorry about that! here's the error message. I believe the issue is from specifying the fields. Message: Call was not successful Method: POST Path: https://graph.facebook.com/v5.0/act_10635738/insights Params: {'date_preset': 'yesterday', 'action_attribution_windows': '["7d_click"]', 'level': 'campaign', 'time_increment': 'monthly', 'filtering': '[{"field":"impressions","operator":"GREATER_THAN","value":1},{"field":"spend","operator":"GREATER_THAN","value":0}]', 'fields': '["adset_id","campaign_id","campaign_name","action_values","reach","frequency","spend","impressions","objective","actions","adset_id","campaign_id","campaign_name","action_values","reach","frequency","spend","impressions","objective","actions"]'}

Status: 400 Response: { "error": { "message": "Syntax error \"Field adset_id specified more than once. This is only possible before version 2.1\" at character 109: adset_id,campaign_id,campaign_name,action_values,reach,frequency,spend,impressions,objective,actions,adset_id,campaign_id,campaign_name,action_values,reach,frequency,spend,impressions,objective,actions", "type": "OAuthException", "code": 2500, "fbtrace_id": "AnzB89Q3Nymmk2pj0D_T2T3" } }

zachliu commented 4 years ago

looks like a bug in the sdk, what version are you using? i'm still on 4.0.8

jkruk24 commented 4 years ago

looks like a bug in the sdk, what version are you using? i'm still on 4.0.8

Interesting. I'm using 5.0.4 and getting the error. I went back and uninstalled facebook_business and tried with 4.0.8 and it worked just fine. Then I tried with 5.0.3 and it didn't work. Tried again with 5.0.2 and it worked. It appears the issue started occurring around 5.0.3

Nathaaaalie commented 4 years ago

@jkruk24 Could you try to either remove the 'fields' from 'params' or keep your fields in params['fields'] and leave fields to be empty for now? Could you specify the reason to keep the fields in two places? SDK will move the 'fields' in to the 'params' in get_insights_async() to fix the bug of this PR, that is the reason why you got a duplicated fields error in v5.0.3. We can remove the duplicated in next released version. =))

facebook-github-bot commented 1 year ago

@zachliu has updated the pull request. You must reimport the pull request before landing.