Upload image_file using Ads API

旧时模样 提交于 2019-12-31 02:03:08

问题


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?


回答1:


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'


来源:https://stackoverflow.com/questions/22592146/upload-image-file-using-ads-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!