代码之家  ›  专栏  ›  技术社区  ›  Alon Shmiel

使用Ads API上载image_file

  •  4
  • Alon Shmiel  · 技术社区  · 11 年前

    我正在尝试为活动广告创建一个新的广告创意( 迁移后 ),使用字段 image_file .

    通过 图形API资源管理器 我发送以下邮件请求:

    网址: https://graph.facebook.com//act_xxxx/adcreatives

    对象id:xxxxx

    正文:此处正文

    title:此处为标题

    name:此处为name

    image_file:@C:\Art.jpg

    我得到以下异常响应:

    “Adcreative创建失败,原因如下:图像文件无效:image_file字段未指定POST文件名。”

    显然我没有正确使用image_file参数。我应该如何使用它?

    2 回复  |  直到 11 年前
        1
  •  4
  •   Nikola Nikolic    11 年前

    尝试只上传图像,然后使用图像哈希来上传创意。

    参数:

    [
     IMAGE_NAME => '@' + path
    ]
    
    POST https://graph.facebook.com//act_xxxx/adimages 
    

    IMAGE_NAME是扩展名为-IMAGE.jpg或IMAGE.png的名称。。。

    作为响应,您将得到

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

    然后使用你收到的图像哈希,并用它创建广告创意。

    如果只想执行一个请求,请执行下一步:

    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'
    
        2
  •  0
  •   vimuth    2 年前

    最好不要使用“image_hash”,而是使用图片作为参数将图像指定为 https://example.com/image.png 。以下是代码示例,需要object_story_spec:

    { "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>>" }
    

    成功的响应应返回图像的ID,如下所示:

    {
    "id": "XXXXXXXXXXXXX"
    }