2017-04-20 56 views
1

我試圖設置在其創建時的播放列表縮略圖,我這樣做:如何使用PHP中的youtube api設置播放列表的縮略圖?

// 1. Create the snippet for the playlist. Set its title and description. 
$playlistSnippet = new Google_Service_YouTube_PlaylistSnippet(); 
$playlistSnippet->setTitle('Test Playlist ' . date("Y-m-d H:i:s")); 
$playlistSnippet->setDescription('A private playlist created with the YouTube API v3'); 
$playlistSnippet->setThumbnails ('https://www.google.co.ve/url?sa=i&rct=j&q=&esrc=s&source=imgres&cd=&cad=rja&uact=8&ved=0ahUKEwidvaDtwbPTAhVhKpoKHWf5CboQjRwIBw&url=http%3A%2F%2Fimagenesbonitas.bosquedefantasias.com%2F&psig=AFQjCNHfcV6nKOO6oU7iwv3LCfb6GBFkAg&ust=1492794187290336'); 

但問題是,在播放列表中的縮略圖是:

"thumbnails": { 
    (key): { 
     "url": string, 
     "width": unsigned integer, 
     "height": unsigned integer 
    } 

所以我不知道如何創建這種方式的對象,然後將其添加到片段對象。

回答

0

setThumbnails完整的原型是:

setThumbnails(Google_Service_YouTube_ThumbnailDetails $thumbnails) 

Google_Service_YouTube_ThumbnailDetails有以下方法:

setDefault(Google_Service_YouTube_Thumbnail $default) 
setHigh(Google_Service_YouTube_Thumbnail $high) 
setMaxres(Google_Service_YouTube_Thumbnail $maxres) 
setMedium(Google_Service_YouTube_Thumbnail $medium) 
setStandard(Google_Service_YouTube_Thumbnail $standard) 

Google_Service_YouTube_Thumbnail的方法:

setHeight(mixed $height) 
setUrl(mixed $url) 
setWidth(mixed $width) 

以下將努力設置縮略圖:

$thumbnailDetails = new Google_Service_YouTube_ThumbnailDetails(); 
$thumbnail = new Google_Service_YouTube_Thumbnail(); 
$thumbnail->setUrl("https://example.com/image.jpg"); 
$thumbnail->setHeight(720); 
$thumbnail->setWidth(1280); 

thumbnailDetails->setDefault($thumbnail); 

$playlistSnippet->setThumbnails($thumbnailDetails); 
+0

你知道我是否可以使用圖像的URL的blob圖像? – Mvram

+0

你的意思是把你的BLOB數據放在'url'字段中?我不認爲這會工作,因爲它期望一個有效的網址,但你可以嘗試 –

+0

不適用於blob格式。順便說一句,$ playlistSnippet-> setThumbnails(thumbnailDetails); - >你忘了符號'$'。但非常感謝,這對我很有用。有沒有可以查閱這些功能的頁面? – Mvram

相關問題