4

I'm trying to create a new Ad Creative for an event ad (Post-Migration), using the field image_file.

Via the Graph API Explorer I send the following post request:

URL: https://graph.facebook.com//act_xxxx/adcreatives

object_id: xxxxx

body: body here

title: title here

name: name here

image_file: @C:\Art.jpg

I get the following exception response:

"The Adcreative Create Failed for the following reason: Invalid image file: The image_file field does not specify a POST file name."

Apparently I'm not using the image_file parameter right. How should I use it?

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
  • Would you mind clearing up your exact request in terms of code and readability? If you can specify the exact language show the sample call, it will be easier to help :) – Sudipta Chatterjee Mar 24 '14 at 07:02

2 Answers2

4

Try uploading image only, and than use image hash to upload creative.

Parameters:

[
 IMAGE_NAME => '@' + path
]

POST https://graph.facebook.com//act_xxxx/adimages 

IMAGE_NAME is name with extension - image.jpg, or image.png...

As the response, you will get

[
 'images' => [
    [
      'hash' => ...,
      'url' => ....
    ]
  ]
]

Than use the image hash you received and create ad creative with that.

If you want to do only one request, do next:

curl \
-F 'access_token=...' \
-F 'title=Test title' \
-F 'body=Test body' \
-F 'link_url=http://www.whatever.com' \
-F 'name=test creative' \
-F 'image_file=Art.jpg' \
-F 'Art.jpg=@C:\Art.jpg ' \
'https://graph.facebook.com/act_xxxx/adcreatives'
  • That is a nice workaround, but I have to send only one http request. it is said in the facebook ad creative documentation that you can do that with just one call to /adcreatives, specifying only the image_file parameter. Anyone knows how to do that? – Alon Shmiel Mar 24 '14 at 12:56
  • 3
    I have added additional explanation of how you can achieve it in one request. The key is that you should reference parameter with file in file_name. Basically, file_name=file_that_you_upload.jpg; file_that_you_upload.jpg=@c:/path/to/file.jpg – Nikola Nikolic Mar 24 '14 at 13:58
0

It is better to not use the " image_hash" but rather use a picture as a parameter to specify an image as https://example.com/image.png. Below is an example of the code, object_story_spec is required :

{ "link_data": { "picture": "https://prppublicstore.blob.core.windows.net/live-za-images/property/384/35/8570384/images/property-8570384-95103406_sd.jpg", "link": "<<LINK>>", "message": "try it out" }, "page_id": "<<PAGE_ID>>" }

A successful response should return an ID of the image as follows:

{
"id": "XXXXXXXXXXXXX"
}
vimuth
  • 5,064
  • 33
  • 79
  • 116