Why is 'gapi.client.youtube' from Youtube Data Api V3 undefined?

荒凉一梦 提交于 2020-01-03 03:17:11

问题


I try to use the Youtube Data Api V3 with javascript

So i have this simple code :

<script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>        
<script type="text/javascript">
    $(window).load(function(){ 
        var viewCount, channelName, subscribers;
        gapi.client.load('youtube', 'v3');
        var request = gapi.client.youtube.channels.list({
            part: 'statistics',
            forUsername : 'GameSprout'
        });
        alert(request);
        alert("test");
    });
</script>

But i have this error :

TypeError: gapi.client.youtube is undefined

How can i fix that ?


回答1:


You are trying to library before it was loaded. Instead of window.load, you should put library functions after googleApiClientReady. Here's a place to get you started: https://developers.google.com/api-client-library/javascript/samples/samples



来源:https://stackoverflow.com/questions/21171160/why-is-gapi-client-youtube-from-youtube-data-api-v3-undefined

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