I am trying to publish Ads on Facebook using Meta Marketing API's.I have created Campaign and Adset using Marketing API's.Now when I trying to add Ad Creative using Marketing API, I got an error like below:

{'error': {'message': "Unsupported post request. Object with ID 'act_xxxx' 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': 'Ak5XpdYe7Hbcs7Eveg--yJg'}}

I provided the correct Ad Account Id and I have the permissions such as ads_management,ads_read and read_insights.Based on the permission, I got the access token from Marketing API product inside the Facebook Developer App.

I used below Python code for adding Ad Creative:

import requests
import json
# Parameters
api_version = 'v18.0'
access_token = 'token'
page_id = 'page_id'
image_hash = 'hash_value'

# API endpoint URL
creative_url = f'https://graph.facebook.com/v18.0/act_xxxx/adcreatives'

data = {
'name': 'test - Creative',
'object_story_spec': json.dumps({
    'page_id': page_id,
    'link_data': {
        'description': '',
        'image_hash': image_hash,
        'link': f'https://facebook.com/{page_id}',
        'message': 'message',
        'name': 'headline',
        'call_to_action': {
            'type': 'LEARN_MORE',
            'value': {
                'link': f'https://facebook.com/{page_id}',
                'link_caption': 'Click Now'
            }
        }
    }
}),
'degrees_of_freedom_spec': json.dumps({
    'creative_features_spec': {
        'standard_enhancements': {
            'enroll_status': 'OPT_OUT'
        }
    }
})
}

# Make the POST request to create the ad creative
response = requests.post(creative_url, data=data)

# Print the response
print(response.json())

Can anyone suggest a solution, to solve this issue?

1

There are 1 best solutions below

0
AbinBenny On

When I modified the code, I got the correct result:

import requests
# Parameters
api_version = 'v18.0'
access_token = 'access_token'
page_id = 'page_id'
image_hash = 'hash_value'

# API endpoint URL
creative_url = f'https://graph.facebook.com/v18.0/act_xxxx/adcreatives'
headers = {'Content-Type': 'application/json'}

data = {
'name': 'Ad Creative 1',
'object_story_spec': {
    'page_id': page_id,
    'link_data': {
        'description': '',
        'image_hash': image_hash,
        'link': f'https://facebook.com/{page_id}',
        'message': 'message',
        'name': 'headline',
        'call_to_action': {
            'type': 'LEARN_MORE',
            'value': {
                'link': f'https://facebook.com/{page_id}',
                'link_caption': f'https://facebook.com/{page_id}'
            }
        }
    }
},
'degrees_of_freedom_spec': {
    'creative_features_spec': {
        'standard_enhancements': {
            'enroll_status': 'OPT_OUT'
        }
    }
}
}
params = {'access_token': access_token}

# Make the POST request to create the ad creative
response = requests.post(creative_url, headers=headers, json=data, params=params)

# Print the response
print(response.json())