I can upload video to facebook page using the graphic api. But I am not able to upload it with a custom video thumbnail. I tried to add "picture" parameter but facebook just ignore this parameter. I can able to change the video thumbnail on facebook page by clicking the "edit" of the video post. So, I think there is some way to do it from the API as well but I just can't find it.
Here is the code I used to upload the video to facebook page:
$data = [
'title' => 'MY POST TITLE',
'description' => 'MY POST DESCRIPTION',
'source' => new CURLFile('video/my_video.mp4', 'video/mp4'),
'access_token' => FACEBOOK_PAGE_TOKEN,
];
// Curl Post Url
$post_url = 'https://graph-video.facebook.com/'.FACEBOOK_PAGE_ID.'/videos';
// CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
So, I think there is some way to do it from the API as well but I just can't find it.
Check the list of parameters listed in the documentation, https://developers.facebook.com/docs/graph-api/reference/page/videos#Creating
thumb
[image]: The video thumbnail raw data to be uploaded and associated with a video.
Using Facebook PHP SDK this process is a little bit simpler:
<?php
use Facebook\FileUpload\FacebookFile;
$fb = new Facebook\Facebook([
'app_id' => 'YOUR_APP_ID',
'app_secret' => 'YOUR_APP_SECRET',
'default_graph_version' => 'v2.5',
]);
$data = [
'thumb' => new FacebookFile('PATH TO YOUR THUMB FILE'),
'source' => $fb->videoToUpload('PATH TO YOUR VIDEO FILE'),
'title' => 'YOUR VIDEO TITLE',
'description' => 'YOUR VIDEO DESCRIPTION!'
];
$response = $fb->post('/YOUR_PAGE_ID/videos', $data, YOUR_PAGE_TOKEN);
$post = $response->getGraphObject();
var_dump( $post );
Just remember to load facebook/graph-sdk as your project dependency in composer.json.
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.