我正在尝试将图片上传到Powershell中的Facebook广告管理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
我也尝试过:
有问题的图片是: https://www.dropbox.com/s/hkx236uiiy1p54e/adimage.jpg?dl=0 和 https://www.dropbox.com/s/gf9on4w8ijbfwl8/adimage.png?dl=0
通过资产管理GUI上传工作。
有什么想法吗?
桑德罗
更新:它确实像Mac上的卷曲魅力一样工作。这使它更不可能是图像本身
答案 0 :(得分:1)
使用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) => ...