How to get the wordlist from youtube search for Jquery UI autocomplete?

旧时模样 提交于 2019-12-25 03:38:06

问题


I just builded my own youtube search based on Youtube API V3. I would like to add auto complete function to search input, the problem is, the wordlist.
If I add a big word list, that means a bigger load time, and the autocomplete is useless, because you need to write out the full word, for get your correct word, if I add a small wordlist, the load time is good, but the problem is same, the autocomplete is useless, because dosen't complete any useful. So I looked this problem in a different way. What about if I somehow I get the youtube autocomplete wordlist, based on relevance, and the wordlist only then loaded, when you typing. Is that possible?


回答1:


With so many research I found a solution for this:

$("#q").autocomplete({
    source: function(request, response){
        /* Need a api key for this, so we add it:  */
        var apiKey = 'MYAPIKEY';
        /* command */
        var query = request.term;
        /* youtube ajax request */
        $.ajax({
            url: "http://suggestqueries.google.com/complete/search?hl=en&ds=yt&client=youtube&hjson=t&cp=1&q="+query+"&key="+apiKey+"&format=5&alt=json&callback=?",  
            dataType: 'jsonp',
            success: function(data, textStatus, request) { 
               response( $.map( data[1], function(item) {
                    return {
                        label: item[0],
                        value: item[0]
                    }
                }));
            }
        });
    },
    /* seçilene işlem yapmak için burayı kullanabilirsin */
    select: function( event, ui ) {

    }
}); 

I hope it help also someone else who looking for a something like this.



来源:https://stackoverflow.com/questions/30469590/how-to-get-the-wordlist-from-youtube-search-for-jquery-ui-autocomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!