3

how to use part : snippet and contentDetails ?? i want to get duration,only music videos,title and watched count.. please help me.

    function keyWordsearch() {
        gapi.client.setApiKey("MY_API_KEY");
        gapi.client.load('youtube', 'v3', function () {
            var q = $('#query').val();
            $("#result").empty();
            var request = gapi.client.youtube.search.list({
                q: q,
                part: 'snippet',

                maxResults: 5,



            });

            request.execute(function (response) {
                for (var i = 0; i < response.items.length; i++) {
                    var id = response.items[i].id.videoId;

                    var name = response.items[i].snippet.title;
                    $('#result').html($('#result').html() + "<li><a href='http://www.youtube.com/watch?v=" + id + "'>" + name + " </a></li>");
                }
                $('#result').html($('#result').html() + '</ul>');
            });
        });
    }

</script>
<script src="https://apis.google.com/js/client.js?onload=onLoadCallback"></script>
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
  • add the code `console.log(response.items[i].snippet)`, then press f12 and look in your console and you should see the different properties of snippet or remove the `.snippet` to see the properties of the item. According to the documentation the duration isn't in the result: https://developers.google.com/youtube/v3/docs/search#resource – Pete Sep 04 '15 at 14:52
  • possible duplicate of [Youtube API v3 , how to get video durations?](http://stackoverflow.com/questions/15596753/youtube-api-v3-how-to-get-video-durations) – Pete Sep 04 '15 at 15:00

1 Answers1

0

enter image description herei write console.log(response.items[i].snippet) then result is like this