How to upload a video to facebook using php sdk 3.2

| | 2 min read

We can upload video to Facebook personnel account or Facebook business page using PHP sdk . Here I am using PHP SDK version 3.2 for uploading process. For downloading PHP SDK go to the link and then click download button.

The next step is create an Facebook App. To create an Facebook app go to the link we can login to this account using our Facebook account credentials.

Find the code to upload video to Facebook in php below. Please ensure to include facebook.php file from PHP sdk. If you want to upload video to personal Facebook account post type should be like this '/me/videos'.If you want to upload video to Facebook page post type like this '/$pageid/photos'. You can find your facebook page id in an About tab of particular Facebook page.

 require 'src/facebook.php';
$file = "video.mp3";
$post_type = '/me/videos';
$post_params = array(
'access_token' => "Acess token of facebook App",
'title' => 'title of the image',
'source' => '@' . $fil ,
$facebook = new Facebook(array(
'appId' => 'Facebook app id',
'secret' => 'Facebook secret key'
$fbpost = $facebook->api($post_type, 'POST', $post_params);
} catch (Exception $e) {
echo $e->getMessage();

The response of the code is the id of the uploaded video.