youtube api로 동영상 제목 가져오는법
본문
유튜브 api key를 발급 받앗는데
원하는 동영상에서 제목을 추출해 낼려면 어떡해야할까요..?
답변 1
/**
* @param $videoId
* @return object{
* publishedAt, channelId,
* title, description, thumbnails, channelTitle, tags, categoryId,
* liveBroadcastContent, defaultLanguage, localized{title, description}, defaultAudioLanguage
* }
* https://developers.google.com/youtube/v3/docs/videos?hl=ko
*/
function getYoutubeInfo($videoId) {
$apikey = 'your_APIkey';
$content = curl('https://www.googleapis.com/youtube/v3/videos?id=' . $videoId . '&key=' . $apikey . '&part=snippet,contentDetails,statistics,status');
$content = json_decode($content, true);
// 영상이 없거나 비공개인경우
if ($content[pageInfo][totalResults] == 0) {
return null;
}
return $content[items][0];
}
우선 유툽 인포메이션 가져오고
$info = getYoutubeInfo($row[videoId]);
$snippet = $info[snippet];
$contentDetails = $info[contentDetails];
$snippet[title]; //제목
$snippet[description]; // 내용
$contentDetails[duration]; // 영상시간
정도로 가져올수있고
https://developers.google.com/youtube/v3/docs/videos?hl=ko 여기 보시면 더 정확하게 나와있어요!-->!-->
답변을 작성하시기 전에 로그인 해주세요.