Youtube Data API - Uncaught TypeError: Cannot read property 'search' of undefined

感情迁移 提交于 2019-12-12 05:08:27

问题


Hi I'm trying to get the Search part of the Youtube Data API to work but not having much luck.

I completely copied the code from Youtube's GitHub page whilst following their tutorial

YT Github Page

The problem seems to be with this function;

function search() {
  var q = $('#query').val();
  var request = gapi.client.youtube.search.list({
    q: q,
    part: 'snippet'
  });

  request.execute(function(response) {
    var str = JSON.stringify(response.result);
    $('#search-container').html('<pre>' + str + '</pre>');
  });
}

Here's the test site

Any help would be much appreciated

Thanks ;)


回答1:


There is a error in your search function, which does not let the JS load initially and which later gives you the undefined error. Following is the correct source code: https://jsfiddle.net/aqwpg8ef/

 request = gapi.client.youtube.search.list({
    q: 'q', //old one was without quotes
    part: 'id, snippet', //the parts should be in quotes as well
    type: 'video',
    order: 'date'
 });

Mostly, on ajax call for search. near lines 20-22

Hope that helps!

Cheers..



来源:https://stackoverflow.com/questions/34713090/youtube-data-api-uncaught-typeerror-cannot-read-property-search-of-undefine

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