how do you get the video ID of a search result with YouTube API v3`

Hi,

I am working with YouTube new API and I can't get the video ID of a list of videos that I search for.

Right now I can get the thumbnail URL so when you click on a search result it goes to a separate page with the thumbnail but I want to get the id so when you click on the thumbnail the video will play.

Here is what I have so far.

Thanks,
<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady">  </script>
 <script>
     function keyWordsearch(){
        gapi.client.setApiKey('AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg');
        gapi.client.load('youtube', 'v3', function() {
                makeRequest();
        });
}
    function makeRequest() {
        var q = $('#query').val();
        var request = gapi.client.youtube.search.list({
                q: q,
                part: 'snippet',
               
                maxResults: 10
        });
        request.execute(function(response)  {                                                                                    
                $('#results_search').empty()
                var srchItems = response.result.items;                      
                $.each(srchItems, function(index, item) {
                 
               
                vidThumburl =  item.snippet.thumbnails.default.url;  
                vidTitle = item.snippet.title;               
                vidThumbimg = '<pre><img id="thumb" src="'+vidThumburl+'" alt="No  Image Available." style="width:204px;height:128px"></pre>';                   

              $('#results_search').append('<a href="'+vidThumburl+'">' + vidTitle + vidThumbimg +  '</a>');                          
        })  
    })  
}
  </script> 




  <div id="buttons">
    <label> <input id="query" type="text"/><button id="search-button"   onclick="keyWordsearch()">Search</button></label>    
    <div id="container_search">
      <ul id="results_search"></ul>
    </div> 

Open in new window

smfmetro10Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
something like this?
     function keyWordsearch(){
        gapi.client.setApiKey('AIzaSyB7oqNYxEGnskHEpKHSCbIH_-VI4_sJkzg');
        gapi.client.load('youtube', 'v3', function() {
                makeRequest();
        });
}
    function makeRequest() {
        var q = $('#query').val();
        var request = gapi.client.youtube.search.list({
                q: q,
                part: 'snippet',
               
                maxResults: 10
        });
        request.execute(function(response)  {                                                                                    
                $('#results_search').empty();
                var srchItems = response.result.items;                      
                $.each(srchItems, function(index, item) {
                 
               
                vidThumburl =  item.snippet.thumbnails.default.url;  
                vidTitle = item.snippet.title;               
                vidThumbimg = '<pre><img id="thumb" src="'+vidThumburl+'" alt="No  Image Available." style="width:204px;height:128px"></pre>';  
                  vidUrl = 'http://www.youtube.com/v/' + item.id.videoId;

              $('#results_search').append('<a href="'+vidUrl+'">' + vidTitle + vidThumbimg +  '</a>');                          
        });  
    });  
}
  

Open in new window

HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smfmetro10Author Commented:
AH!! item.id.videoID !!

Thanks!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.