Youtube API search auto-complete

17,888

Solution 1

Ok I found this URL:

http://suggestqueries.google.com/complete/search?client=firefox&ds=yt&q=Query

It isn't part of Youtube API, but still works, returns a JSON response.

Solution 2

For json just add "client" parameter:

http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&client=firefox&q=Query

Solution 3

Above all apis are old and give google search suggestion not youtube search suggestion

Use this:

https://clients1.google.com/complete/search?client=youtube&gs_ri=youtube&ds=yt&q=faded

Extract suggestions using following JS code:

//  data is response of above api
   const data = 'window.google.ac.h(["faded",[["faded",0,[433]],["faded alan walker lyrics",0,[433]],["faded remix",0,[433]],["faded 8d",0,[433]],["faded piano",0,[433]],["faded wheel free fire",0],["faded karaoke",0,[433]],["faded ringtone",0,[433]],["faded instrumental",0,[433]],["faded live",0,[433]],["faded piano tutorial",0,[433]],["faded whatsapp status",0,[433]],["faded dhol cover",0,[433]],["faded dance",0,[433]]],{"k":1,"q":"_sPyvXmmbfcsVtfP4sgjOdKQAvg"}])';

    const searchSuggestions = [];
    data.split('[').forEach((ele, index) => {
      if (!ele.split('"')[1] || index === 1) return;
        return searchSuggestions.push(ele.split('"')[1]);
    });
    console.log(searchSuggestions);
Share:
17,888

Related videos on Youtube

Emanuel
Author by

Emanuel

Updated on September 14, 2022

Comments

  • Emanuel
    Emanuel over 1 year

    I'm using Youtube API, I'd like to have a search auto-complete feature, just like on YouTube, when you type into the search input box, it gives you search suggestions. I've read the docs, but still missing, Is this possible using the API?

  • Aditya M P
    Aditya M P over 9 years
    That's pretty dang cool... how did you find it, by looking at the network requests for the youtube search?
  • Faisal Ashraf
    Faisal Ashraf about 9 years
    we are not getting data in json , it is downoading in .txt file?
  • Faisal Ashraf
    Faisal Ashraf about 9 years
    how can we get suggest in json form , from this link .suggestqueries.google.com/complete/…
  • Zed
    Zed almost 8 years
    This is exactly what is needed, made an example based on this codepen.io/OfficialAntarctica/pen/oxQQPB
  • Vicky Chijwani
    Vicky Chijwani almost 7 years
    This doesn't work with AJAX requests because the response lacks CORS headers :(
  • Vyacheslav Konovalov
    Vyacheslav Konovalov almost 7 years
    It's "The Google Way" :D Sure they have some reasons for that hack codepen.io/vyachkonovalov/pen/XRYpgB?editors=0012
  • Vijaysinh Parmar
    Vijaysinh Parmar almost 7 years
    is it possible to get data response direct in json?? its downloading .txt file
  • Marson Mao
    Marson Mao over 3 years
    Can localhost uses this api? I'm having the Origin https://localhost:8080 is not allowed by Access-Control-Allow-Origin. error.