作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将图像上传到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"}}
curl -F "filename=@adimage.jpg" -F "access_token=abc" https://graph.facebook.com/v2.7/act_12345678/adimages
最佳答案
使用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) => ...
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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!