How to get insights on Facebook Business API using Python?

2.6k Views Asked by At

I have this code below with my credentials;

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.campaign import Campaign

my_app_id = ''
my_app_secret = ''
my_access_token = ''
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('')
my_campaign = Campaign('')

When I run the code below, I get an error.

Input:

my_account_insights = my_account.get_insights()
print(my_account_insights)

Output:

FacebookRequestError: 

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v12.0/act_2193000197632450/adsets
  Params:  {'summary': 'true'}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#100) Missing permissions",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "AvMDtZu8KYqYG8qt3repNjL"
      }
    }

What am I missing? Could you please help me to figure it out?

1

There are 1 best solutions below

4
On

Generate a new token https://developers.facebook.com/tools/explorer/ and set the permission accordingly