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

2

1

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 ?

Liquorice answered 16/1, 2014 at 19:33 Comment(0)
T
2

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

Thomasinathomasine answered 16/1, 2014 at 20:41 Comment(0)
T
0

you must call gapi.client.init() before use it.

Thomism answered 20/4, 2022 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.