我正在尝试使用 Meta Marketing API 在 Facebook 上发布广告。我已经使用 Marketing API 创建了
Campaign
和 Adset
。现在,当我尝试使用 Marketing API 添加 Ad Creative
时,出现如下错误:
{'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'}}
我提供了正确的广告帐户 ID,并且拥有
ads_management
、ads_read
和 read_insights
等权限。根据权限,我从 Facebook 开发者应用程序内的 Marketing API
产品获取了访问令牌。
我使用下面的Python代码来添加
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())
任何人都可以提出解决方案来解决这个问题吗?
当我修改代码时,我得到了正确的结果:
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())