在YouTube上的API一個簡單的視頻搜索,你會得到視頻的標題,描述,視頻ID和圖像源,最好的辦法完整的代碼如下。
<?php
error_reporting(0);
$search = "Search Query"; // Search Query
$api = "YouTube API Key"; // YouTube Developer API Key
$results = 10; // Max results
$link = "https://www.googleapis.com/youtube/v3/search?safeSearch=moderate&order=relevance&part=snippet&q=".urlencode($search). "&maxResults=$results&key=". $api;
$video = file_get_contents($link);
$video = json_decode($video, true);
foreach ($video['items'] as $data){
$title = $data['snippet']['title'];
$description = $data['snippet']['title'];
$vid = $data['id']['videoId'];
$image = "https://i.ytimg.com/vi/$vid/default.jpg";
// Output Title/Description/Image URL If Video ID exist
if($vid){
echo "Title: $title<br />Description: $description<br />Video ID: $vid<br />Image URL: $image<hr>";
}
}
?>
搜索視頻(相關性)使用這個網址,你可以得到VideoID的和標題,圖片的網址等https://www.googleapis.com/youtube/v3/search?part=snippet&contentdetails&q=SEARCH KEY&類型=視頻和videoSyndicated = true&key =您的API密鑰&maxResults = 25 – Yogendra
https://www.googleapis.com/youtube/v3/search?part=snippet&contentdetails&q={SERCH KEY}&type = video&videoSyndicated = true&key = {YOUR API KEY}&maxResults = 25 – Yogendra