gpt4 book ai didi

facebook - 使用Facebook Ads Management API上传图像

转载 作者:行者123 更新时间:2023-12-02 23:42:08 24 4
gpt4 key购买 nike

我正在尝试将图像上传到Powershell中的Facebooks广告管理api,以便稍后在创建实际广告时使用图像哈希。

$fileName = "adimage.jpg"
$fileContent = get-content $fileName
$fileContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)

$parameters = @{
access_token = "abc"
bytes = $fileContentEncoded
}

$result = Invoke-WebRequest -Uri "https://graph.facebook.com/v2.7/act_12345678/adimages" -Method Post -ContentType "image/jpeg" -body $parameters

我总是得到:
{"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_subcode":1487242,
"is_transient":false,"error_user_title":"Image Resize Failed",
"error_user_msg":"Image Resize Failed:Could not get image size","fbtrace_id":"Bl\/fu39rM2W"}}

adimages端点的API页面为:
https://developers.facebook.com/docs/marketing-api/reference/ad-image

我们基本上是在寻找与
curl -F "filename=@adimage.jpg" -F "access_token=abc" https://graph.facebook.com/v2.7/act_12345678/adimages

我也尝试过:

使用png图像的
  • 使用“字节数=(获取内容adimage.jpg-原始)”
  • 通过-infile参数发布图像,并将访问 token 添加为参数而不是表单字段
  • 此操作的结果(以及其他一些变体)是我没有收到错误并收到200响应,但是
  • 内容字段为空且没有文件上传

    有问题的图像是:
    https://www.dropbox.com/s/hkx236uiiy1p54e/adimage.jpg?dl=0

    https://www.dropbox.com/s/gf9on4w8ijbfwl8/adimage.png?dl=0

    通过 Assets 管理GUI进行的上传有效。

    有任何想法吗?

    桑德罗

    更新:在Mac上,它确实确实像带有 curl 的护身符一样工作。这使得它更不可能是关于图像本身的

    最佳答案

    使用node.js调用Graph API时遇到了相同的问题。我试图对文件字节进行UTF-8编码,然后对结果进行base64编码,但是出现了相同的错误。

    当我删除UTF-8文件编码并使用原始字节(仍为base64编码)时,对我来说效果很好。

    因此,此操作因相同的“图像调整大小失败”错误而失败:

    fs.readFile(imagePath, 'UTF8', (err, fileData) => {
    let postData = {
    name: 'My Image',
    bytes: new Buffer(fileData).toString('base64')
    };
    request.post(url, {form: postData}, (err, response, body) => ...

    但这有效(没有UTF-8编码):
    fs.readFile(imagePath, (err, fileData) => {
    let postData = {
    name: 'My Image',
    bytes: new Buffer(fileData).toString('base64')
    };
    request.post(url, {form: postData}, (err, response, body) => ...

    关于facebook - 使用Facebook Ads Management API上传图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39080240/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com