我創建了一個PHP函數來回答你的問題,不用您去通過閱讀關於Facebook圖形枯燥的文檔。 您只需插入視頻鏈接,Facebook和YouTube,但您可以修改以添加其他來源。 只需在地址欄中爲YouTube複製YouTube視頻鏈接,然後右鍵點擊視頻並點擊顯示視頻網址,然後複製該視頻鏈接。
//get video thumbnail for facebook and youtube
function get_vid_thumbnail($link){
$thumbnail='';
//check if video link is facebook
if (strpos($link, 'facebook') !== false) {
$thumbnail=fb_thumb($link);
//$thumbnail='fb';
}
//check if video link is youtube
if (strpos($link, 'youtube.com') !== false) {
$thumbnail=youtube_thumb($link);
//$thumbnail='youtube';
}
return $thumbnail;
}
//supporting functions
//get youtube thumbnail
function youtube_thumb($link){
$new=str_replace('https://www.youtube.com/watch?v=','', $link);
$vv='https://img.youtube.com/vi/'.$new.'/0.jpg';
return $vv;
}
//clean the facebook link
function fb_video_id($url) {
//split the url
$main=parse_url($url);
//get the pathe and split to get the video id
$main=$main['path'];
$main=explode('/',$main);
$main=$main[3];
return $main;
}
//get the thumbnail
function fb_thumb($link) {
$img = 'https://graph.facebook.com/'.fb_video_id($link).'/picture';
return $img;
}
//get video thumbnail for fb and youtube ends
//get embed url for facebook and youtube to be used as video source
function get_vid_embed_url($link){
$embed_url='sss';
//check if video link is facebook
if (strpos($link, 'facebook') !== false) {
# code...
$embed_url=fb_embed_link($link);
//$thumbnail='fb';
}
//check if video link is youtube
if (strpos($link, 'youtube.com') !== false) {
# code...
$embed_url=youtube_embed_link($link);
//$thumbnail='youtube';
}
return $embed_url;
}
//get youtube embed link
function youtube_embed_link($link){
$new=str_replace('https://www.youtube.com/watch?v=','', $link);
$link='https://www.youtube.com/embed/'.$new;
return $link;
}
//get facebook embed link
function fb_embed_link($link) {
$link = 'https://www.facebook.com/plugins/video.php?href='.$link.'&show_text=0&width=560';
return $link;
}
謝謝,它幫助了我:)...我可以通過這種方式獲得視頻標題嗎? –
要獲得視頻標題,請致電https://graph.facebook.com/VIDEO_ID並查找返回的「名稱」字段。 「圖片」字段也將與此調用一起返回並對應於縮略圖。欲瞭解更多詳情,請參閱https://developers.facebook.com/docs/reference/api/video/ –
這是相當小的圖片,我可以像youtube一樣獲得更大的縮略圖嗎? – TomSawyer