提供的图像文件无效。请再次检查您的图像路径。 Facebook Graph API错误
我正在尝试将图像与Laravel的HTTP客户端上传到Facebook Graph API。但是我之前提到的错误。
$ad_account_id = env("AD_ACCOUNT_ID");
$access_token = env("ACCESS_TOKEN");
$image = $request->file('image');
$response = Http::asForm()
->withHeaders(['Content-Type: multipart/form-data'])
->post('https://graph.facebook.com/v14.0/act_' . $ad_account_id . '/adimages',
[
'filename' => file_get_contents($image),
'access_token' => $access_token
]
);
dd(json_decode($response->body()));
在文档中,Facebook为我提供了这样的卷曲API示例,例如此
curl \
-F 'filename=@<IMAGE_PATH>' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/adimages
问题与Image_path有关。我尝试以Base64格式发送任何上传图像的路径。我可以在Postman中使用同一API上传同一图像。关于access_token
或ad_account_id
没有任何问题。
I am trying to upload image to Facebook graph api with Http Client of Laravel. But I am getting the error mentioned before.
$ad_account_id = env("AD_ACCOUNT_ID");
$access_token = env("ACCESS_TOKEN");
$image = $request->file('image');
$response = Http::asForm()
->withHeaders(['Content-Type: multipart/form-data'])
->post('https://graph.facebook.com/v14.0/act_' . $ad_account_id . '/adimages',
[
'filename' => file_get_contents($image),
'access_token' => $access_token
]
);
dd(json_decode($response->body()));
In documentation Facebook gives me curl api example like this
curl \
-F 'filename=@<IMAGE_PATH>' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/adimages
Problem is all about IMAGE_PATH. I have tried to send any kind of path of uploaded image even in base64 format. I am able to upload the same image with same api in Postman. There is not any problem about access_token
or ad_account_id
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
建议将PHP SDK用于此类操作。
https://github.com/faceblebook/face-pace-phpbebook-php-php-business-sdk
Will recommend to use PHP SDK for such operations.
https://github.com/facebook/facebook-php-business-sdk
通过使用
附加
http客户端的方法解决了我的问题:Solved my problem by using
attach
method of HTTP client: