비디오 ID가있는 경우 YouTube 비디오 제목을 얻으려면 어떻게해야합니까?

StackOverflow https://stackoverflow.com/questions/1760231

  •  21-09-2019
  •  | 
  •  

문제

나는 지금 YouTube API와 함께 놀고 있으며 작은 프로젝트를 시작했습니다 (재미).

문제는 ID에서 비디오 제목을 얻는 방법을 찾을 수 없다는 것입니다. (예 : yllzyhk54z0)

데이터 및 플레이어 API 문서를 살펴 보았지만 찾을 수 없습니다.

누군가 가이 작업을 수행하는 방법을 알고 있거나 누군가 가이 작업을 수행하는 방법을 찾도록 도와 줄 수 있다면 저를 도와주세요.

참고 : JavaScript를 사용하고 있습니다. 웹 앱이 될 것입니다.

편집 : 아이디어가 있습니다. 아마도 정기적 인 수용량을 사용하여 페이지 제목에서 제목을 구문 분석 할 수 있습니다. 나는 이것을 연구하고있다.

도움이 되었습니까?

해결책

다른 도메인에서 문서를 얻으려고하므로 JavaScript에서는 완전히 불가능합니다. 약간의 PHP를 던져서 기쁘다면 이것을 시도하십시오. OK 테스트 :

<?
    $vidID = $_POST['vidID'];
    $url = "http://gdata.youtube.com/feeds/api/videos/". $vidID;
    $doc = new DOMDocument;
    $doc->load($url);
    $title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
?>

<html>
    <head>
        <title>Get Video Name</title>
    </head>
    <body>
        <form action="test.php" method="post">
            <input type="text" value="ID Here" name="vidID" />
            <input type="submit" value="Get Name" />
        </form>
        <div id="page">URL: [<?= $url ?>]</div>
        <div id="title">Title: [<?= $title ?>]</div>
    </body>
</html>

다른 팁

이것이 JavaScript 및 V3 YouTube Data API로 수행 할 수있는 방법입니다.

var ytApiKey = "...";
var videoId = "ylLzyHk54Z0";

$.get("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + videoId + "&key=" + ytApiKey, function(data) {
  alert(data.items[0].snippet.title);
});

부르다 http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0.

이 XML 파일에서 <title> 꼬리표.

YouTube API 문서

JSON 요청을 사용할 수 있습니다. http://gdata.youtube.com/feeds/api/videos/ylLzyHk54Z0?v=2&alt=jsonc

이 답변은 2015 년 12 월 현재 정확합니다.

YouTube 비디오 ID에서 비디오 제목을 얻으려면 YouTube Data API를 사용하여 다음 URL을 구성해야합니다 (API 키를 사용해야합니다. 그렇지 않으면 요청이 실패합니다).

https://www.googleapis.com/youtube/v3/videos?part=snippet&id={YOUTUBE_VIDEO_ID}&fields=items(id%2Csnippet)&key={YOUR_API_KEY}

GET 요청을 수행하면 아래 청크와 유사한 JSON 응답을 받게됩니다. 제목의 경우, 그것은에 존재합니다 snippet/title 열쇠.

{
   "items":[
      {
         "id":"Jglv0A0qLI8",
         "snippet":{
            "publishedAt":"2014-06-30T03:42:20.000Z",
            "channelId":"UCdTU5vd37FlTZ-xoB0xzRDA",
            "title":"AIA Malaysia - A-Plus Venus Plan - Comprehensive Female Protection and Insurance Plan",
            "description":"A comprehensive female protection plan for the modern women\n\nFor more information visit: http://www.aia.com.my/en/individuals/products-and-services/health/a-plus-venus-a-plus-venus-extra.html\n\nFor more products, visit AIA Malaysia's Products and Services playlist:\nhttps://www.youtube.com/playlist?list=PLSrgVT3aQ1fZ3SCe-dEVnFJDApBYkqolP\n\nFor more videos. subscribe to AIA Malaysia's YouTube channel:\nhttps://www.youtube.com/channel/UCdTU5vd37FlTZ-xoB0xzRDA",
            "thumbnails":{
               "default":{
                  "url":"https://i.ytimg.com/vi/Jglv0A0qLI8/default.jpg",
                  "width":120,
                  "height":90
               },
               "medium":{
                  "url":"https://i.ytimg.com/vi/Jglv0A0qLI8/mqdefault.jpg",
                  "width":320,
                  "height":180
               },
               "high":{
                  "url":"https://i.ytimg.com/vi/Jglv0A0qLI8/hqdefault.jpg",
                  "width":480,
                  "height":360
               },
               "standard":{
                  "url":"https://i.ytimg.com/vi/Jglv0A0qLI8/sddefault.jpg",
                  "width":640,
                  "height":480
               },
               "maxres":{
                  "url":"https://i.ytimg.com/vi/Jglv0A0qLI8/maxresdefault.jpg",
                  "width":1280,
                  "height":720
               }
            },
            "channelTitle":"AIA Malaysia",
            "tags":[
               "aia",
               "aia malaysia",
               "a-plus venus",
               "female health insurance",
               "female life insurance",
               "female insurance",
               "female medical insurance"
            ],
            "categoryId":"27",
            "liveBroadcastContent":"none",
            "localized":{
               "title":"AIA Malaysia - A-Plus Venus Plan - Comprehensive Female Protection and Insurance Plan",
               "description":"A comprehensive female protection plan for the modern women\n\nFor more information visit: http://www.aia.com.my/en/individuals/products-and-services/health/a-plus-venus-a-plus-venus-extra.html\n\nFor more products, visit AIA Malaysia's Products and Services playlist:\nhttps://www.youtube.com/playlist?list=PLSrgVT3aQ1fZ3SCe-dEVnFJDApBYkqolP\n\nFor more videos. subscribe to AIA Malaysia's YouTube channel:\nhttps://www.youtube.com/channel/UCdTU5vd37FlTZ-xoB0xzRDA"
            }
         }
      }
   ]
}

자세한 내용은 방문하십시오 API 문서 페이지.

비디오 제목은 API에 있으며 DOT 표기법을 사용하여 JavaScript로 도달 할 수 있습니다.

the_name_of_your_video_object.A.videoData.title

Robert Sim과 Cbaigorri의 답변이 최고 였는데, 현재 JS와 함께 할 수있는 올바른 방법입니다.

https://www.googleapis.com/youtube/v3/videos?part=snippet&id={YOUTUBE_VIDEO_ID}&fields=items(id,snippet)&key={YOUR_API_KEY}

이것에 대한 약간의 사양 : Comma 분리 YouTube 비디오 ID를 사용하여 한 번의 요청에서 여러 비디오 정보를 얻을 수 있습니다.

비디오 1 개를 얻으려면 교체하십시오 {YOUTUBE_VIDEO_ID} 비디오 ID (예 : 123456) 한 번의 요청으로 더 많은 비디오를 얻으려면 교체 {YOUTUBE_VIDEO_ID} 쉼표로 분리 된 ID (예 : 123456,234567,345678,456789)

이렇게하면 할당량에서 단일 요청으로 계산됩니다.이 방법으로 1 할당량/요청 비용만으로 많은 비디오 세부 정보를 얻을 수 있습니다.

내 해결책은 다음과 같습니다.

$xmlInfoVideo    = simplexml_load_file("http://gdata.youtube.com/feeds/api/videos/".$videoId."?v=2&fields=title");

foreach($xmlInfoVideo->children() as $title) { $videoTitle = strtoupper((string) $title); }

이것은 비디오 제목을 얻습니다.

사용하는 대신 http://gdata.youtube.com/feeds/api/videos/....

비디오를로드 한 경우 플레이어 개체의 getVideoData () 메소드를 사용하여 제목을 포함하여 비디오의 정보를 검색 할 수 있습니다. video_id, 저자, 제목이 포함 된 개체를 반환합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top