Youtube API, gapi is not defined?

后端 未结 1 2044
陌清茗
陌清茗 2021-01-17 06:22

I\'m trying to do a Youtube API and I feel like I got everything working except this gapi and res thing? It says gapi is not defined. How can I make this work?



        
相关标签:
1条回答
  • 2021-01-17 06:55

    gapi is an object created by the Google API javascript library that manages all interactions (i.e. does all the heavy lifting of the requests) for you. If the object is not defined, you may not have included the library itself in your page. Somewhere in your HTML, you'll need a script tag that loads the library located at:

    https://apis.google.com/js/client.js

    Note that, in loading the library with a script tag, you should also pass it a callback ... this is a function that will be automatically called as soon as the library is done loading. So in your case, your init() method is that callback, and so your script tag would look like this:

    <script src="https://apis.google.com/js/client.js?onload=init"></script>
    

    The browser will get the library, load it, then run init() when the library is done loading, and all will be ready for your form to execute when triggered.

    0 讨论(0)
提交回复
热议问题