Creating an ad for Facebook with the Facebook Business SDK

55 Views Asked by At

I hope somebody can help me.

I've basically spent all day to achieve a programmatic creation of a Facebook ad in PHP.

If wanted I can provide my code of course, but so far it doesn't get me anywhere.

Maybe someone has a working example in PHP on how to programmatically create an ad successfully. I have managed to create a new campaign, I have managed to create a new ad set, I have managed to create an image and to receive the corresponding hash.

But when it comes to the ad creative I am unable to receive an ID that I can pass on to the ad.

When using "OBJECT_STORY_SPEC" the error gives me, that I need to set the enroll_status. This I have not successfully achieved.

When going without OBJECT_STORY_SPEC I simply get an array for the adcreative, which has no id that I can pass on to

AdFields::CREATIVE => array( 'creative_id' => $adCreative->id, ),

Thank you!

1

There are 1 best solutions below

1
Tushar Raina On

I'm using python these parameters worked for me:

params = {
    "name": title + "_creative",
    "object_story_spec": {
        "page_id": page_id,
        "link_data": {
            "picture": image_url,
            "link": link_url,
            "message": message,
        }
    },
    "degrees_of_freedom_spec": {
        "creative_features_spec": {
            "standard_enhancements": {
                "enroll_status": "OPT_OUT"
            }
        }
    }
}