Reputation: 87
I am trying to upload a video to Facebook page. I was successfull in uploading the video using a curl call via POSTMAN. Here's the curl used in POSTMAN:
curl -X POST \
"https://graph-video.facebook.com/v8.0/<page_id>/videos" \
-F "access_token=<access_token>" \
-F "source=@/home/shubham/Downloads/big_buck_bunny_720p_1mb (1).mp4"
-F "title=Sample video"
(In Postman, I select the file I want to upload. See attached image)
However, when I tried to do the same using PHP, I am getting an error. I am using the code below to do it.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph-video.facebook.com/v7.0/<page_ID>/videos');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
'access_token' => $access_token,
'source' => '@' .realpath($params['video_path']),
'title' => $params['video_title'],
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
where: $params['video_path'] = '/home/shubham/Downloads/big_buck_bunny_720p_1mb (1).mp4'; $params['video_title'] = 'Sample video upload from backend';
Here is the error I am getting from Facebook:
{"error":{"message":"There was a problem uploading your video file. Please try again.","type":"OAuthException","code":390,"error_subcode":1363030,"is_transient":true,"error_user_title":"Video Upload Timeout","error_user_msg":"Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video you're trying to upload is too large. Please try again.","fbtrace_id":"A9sy8q1MUG5UJkgNI35dfZ2"}}
Upvotes: 3
Views: 901
Reputation: 19929
if its working in postman you can create the php curl command from postman by clicking the code near to the right corner of the request
Upvotes: 3