My code Thats producing the error, I have * out all of the details for obvious resins ,but i can assure you that the details are correct as of my knowledge
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.campaign import Campaign
from facebook_business.api import FacebookAdsApi
access_token = '#############'
app_secret = '##############'
app_id = '###############'
id = '############'
FacebookAdsApi.init(access_token=access_token)
fields = [
]
params = {
'name': 'My campaign',
'objective': 'OUTCOME_TRAFFIC',
'status': 'PAUSED',
'special_ad_categories': [],
}
print (AdAccount(id).create_campaign(
fields=fields,
params=params,
))
So this is the sample code for the marketing api documentation here: https://developers.facebook.com/docs/marketing-apis/get-started
Ive put in my own details:
Access token
app secret
app id
heres the issue, i put in my ad account id and i get an error ill show it below, if i put the sandbox ad account id i get the same error. I have checked the graph api documentation as it asks me to but to no avail im not the greatest at understanding documentation but i try i havent found anything in the graph api documentation to assist me
exception has occurred: FacebookRequestError
Message: Call was not successful
Method: POST
Path: https://graph.facebook.com/v18.0/1319248112287380/campaigns
Params: {'name': 'My campaign', 'objective': 'OUTCOME_TRAFFIC', 'status': 'PAUSED', 'special_ad_categories': '[]'}
Status: 400
Response:
{
"error": {
"message": "Unsupported post request. Object with ID '1319248112287380' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "AEe1jri5iGEm023TkvE98-x"
}
}
File "C:UsersdanieDocumentseasyappsfacebook_mvp.py", line 25, in <module>
print (AdAccount(id).create_campaign(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
facebook_business.exceptions.FacebookRequestError:
Message: Call was not successful
Method: POST
Path: https://graph.facebook.com/v18.0/1319248112287380/campaigns
Params: {'name': 'My campaign', 'objective': 'OUTCOME_TRAFFIC', 'status': 'PAUSED', 'special_ad_categories': '[]'}
Status: 400
Response:
{
"error": {
"message": "Unsupported post request. Object with ID '1319248112287380' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "AEe1jri5iGEm023TkvE98-x"
}
}
Any help is appreciated
I want the code to Send a request to the api, from there i will be expanding it, ive tried to swap all the ids out ive tried creating a new account but no luck, from there i will be turning it all to a library etc anyway,
2
Answers
So after much investigation i figured it out, The facebook Ads API is outdated with python atleast using python2, I tried Using curl as a subprocess with python and Success works flawlessly heres the code
Based on your sample, it looks like you are trying to create campaigns under a specific ad account. The error message is indicating that either you have the wrong ad account ID, or you do not have the correct permissions.
When you generate the access token, I believe you will need
ads_management
permissions for what you are trying to achieve.My advice is to use the graph API explorer tool to grant the proper permissions and to test the call.
You can verify which permissions your access token has by using the access token debugger tool. Make sure it has atleast
ads_read
andads_management
in thescopes
field.Another tip, you can grab the ad account ID from the url when you load ads manager. It is the
act
GET param.