简体   繁体   中英

Cannot Upload video to Facebook page using PHP but can using curl

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"}}

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM