0

I'm using php sdk (default graph version 2.9)

    "facebook/graph-sdk": "5.5.0",
    "facebook/php-ads-sdk": "2.8.2"

I'm trying to create an ad creative without creating the image first and using it's hash.

            $creative = $this->_fb_account->createAdCreative($all_fields, [
            'name'          => 'my first ad creative',
            'title'         => 'my title',
            'body'          => 'my body',
            'image_file'    => '/path/to/my_file.png',
            'object_type'   => AdCreativeObjectTypeValues::DOMAIN,
            'object_url'    => 'http://example.com',
        ]);

I get the following error:

#errorUserTitle: "Invalid image file" #errorUserMessage: "The image_file field does not specify a POST file name."

I can't find anything about this in the docs. Here is a related stackoverflow question which also did not fix the problem.

Community
  • 1
  • 1
Natanael
  • 154
  • 2
  • 8

1 Answers1

0

The image_file needs to be uploaded in a separate POST request (basically, the PHP $_FILES object needs to be populated with the image being uploaded).

One way to achieve this in one request via CURL:

curl  \
-F 'image_file=MyImage.png' \
-F 'body=my body' \
-F 'name=my first creative' \
-F 'object_url=http://example.com' \
-F 'title=My Title' \
-F "access_token=<ACCESS_TOKEN>" \
-F "MyImage.png=@/path/to/my_file.png" \
https://graph.facebook.com/v2.9/act_<ACCT_ID>/adcreatives