1

我想用 api 创建一个广告素材。当我发布 object_story_spec 参数时,我收到此错误“创意规范必须是关联数组(可选 json 编码)”

这是我的 json 值,它是有效的。

{ "page_id" : "103830656322074", "link_data": { "call_to_action": {"type":"LEARN_MORE","value":{"link":"facebook.com/"}}, "caption": "Reklam #1", "name": "Reklam #1", "link": "facebook.com/", "message": "facebook.com/" }}

developer.facebook.com/docs/marketing-api/reference/ad-creative#Creating

4

3 回答 3

1

您应该在传递到广告素材之前对 $object_story_spec 进行 url 编码,如下所示。

$object_story_spec = urlencode($object_story_spec);
$creative = new AdCreative(null, 'ad_Acount_id');
        $creative->setData(array(
            AdCreativeFields::NAME => 'Sample Creative',
            AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
        ));

于 2016-04-21T10:30:28.727 回答
0

它应该像什么。

object_story_spec={ 
                    "page_id": "<PAGE_ID>", 
                    "video_data": { 
                      "call_to_action": {"type":"LIKE_PAGE","value":{"page":"<PAGE_ID>"}}, 
                      "description": "try it out", 
                      "image_url": "<THUMBNAIL_URL>", 
                      "video_id": "<VIDEO_ID>" 
                    } 
                  }


Or

$object_story_spec = new ObjectStorySpec();
        $object_story_spec->setData(array(
            ObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
            ObjectStorySpecFields::LINK_DATA => <LINK_DATA>,
        ));

 $creative = new AdCreative(null, 'ad_Acount_id');
        $creative->setData(array(
            AdCreativeFields::NAME => 'Sample Creative',
            AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
        ));
于 2016-02-10T16:36:08.080 回答
0

只需将目标字段转换为字符串,例如,如果您使用请求:

import requests
params = {
    'name': 'My Ad Set',
    'optimization_goal': 'LINK_CLICKS',
    'billing_event': 'IMPRESSIONS',
    'bid_amount': 2,
    'daily_budget': 100,
    'campaign_id': campaign_id,
    "targeting": str({
            "age_max": 65,
            "age_min": 18,
            "flexible_spec": [..]
    }),
    'start_time': datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
    'status': 'PAUSED',
    'access_token': access_token,
}

response = requests.post(
    url=f'https://graph.facebook.com/v11.0/act_{ad_account_id}/adsets',
    params=params
)
于 2021-07-27T14:38:49.217 回答