Why is 'gapi.client' from Google Plus Api undefined ?

前端 未结 1 1886
甜味超标
甜味超标 2021-02-20 17:39

I am trying to use google+ api, and i had to modify the sample authentification example to fit my needs like this:



        
1条回答
  •  温柔的废话
    2021-02-20 18:14

    You must use the ?onload callback parameter, it is called when the JS Client has finished loading asynchronously. By running on dom ready, you are trying to access gapi.client before it has been defined. What's happening is that the /js/client.js script defines gapi and some helper functions, but gapi.client and gapi.auth aren't defined until the JS client has finished loading. When you inspect the Object logged by console.log(gapi), the client has finished loading, so you see gapi.client and gapi.auth defined.

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