Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API - Insights: Status: 500, error code 1, "An unknown error occurred" at random times

Of the late when trying to fetch data from FB's Marketing API, I get following error:

  Status:  500
  Response:
    {
      "error": {
        "code": 1,
        "message": "An unknown error occurred"
      }
    }

at times. If I try to immediately make the same request via Postman, it returns data at times and at times throws 500 status error. Below is the data being sent to FB

  facebookads.exceptions.FacebookRequestError:

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v2.3/act_XYZ/insights
  Params: {
      'time_increment': 1,
      'level': 'adgroup',
      'fields': '["account_name", "deeplink_clicks",
                  "campaign_name",
                  "social_impressions",
                  "campaign_group_name",
                  "campaign_id",
                  "adgroup_name",
                  "unique_impressions",
                  "social_reach",
                  "unique_social_impressions",
                  "placement",
                  "total_actions",
                  "cpm",
                  "impressions",
                  "ctr",
                  "reach",
                  "clicks",
                  "social_clicks",
                  "spend",
                  "website_clicks",
                  "adgroup_id",
                  "actions",
                  "cpc",
                  "cpp",
                  "unique_clicks",
                  "app_store_clicks",
                  "unique_social_clicks",
                  "account_id",
                  "campaign_group_id"
              ]',
  'breakdowns': '["placement"]',
  'time_range': '{"since":"2015-09-01","until":"2015-09-09"}',
  'summary': None
  }

  Status:  500
  Response:
    {
      "error": {
        "code": 1,
        "message": "An unknown error occurred"
      }
    }

I am using Facebook's Python SDK from

-e git+https://github.com/pythonforfacebook/facebook-sdk.git@449f56f0db086a41bedd23df714e7f77c1051f5b#egg=facebook_sdk-dev

Can someone please let me know what I might be missing in this case?

Thanks.

like image 485
Nikhil Anurag V N Avatar asked Oct 15 '25 18:10

Nikhil Anurag V N


2 Answers

I'm running into the same issue and I have noticed a pattern where it errors out when the request takes more than ~30s in Postman. Not sure what you can do to fix this but I have had some success by:

  • Pulling back the level of granularity / breakdowns
  • Limiting to a lower # of records per page

Unfortunately I haven't seen a consistent pattern with the levels of granularity that cause this delay. Sometimes I can report @ ad level with 5000 results per page, other times I need to throttle back significantly

like image 93
Johan Avatar answered Oct 17 '25 07:10

Johan


You may want to learn about the HTTP protocol - in this case about response status codes. 500 means "internal server error", IOW it's the facebook API server that failed, not your code. Your only options at this point are to either log the error and call it a day or setup a wait/retry loop.

like image 30
bruno desthuilliers Avatar answered Oct 17 '25 08:10

bruno desthuilliers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!