简体   繁体   中英

How to Load Google API Javascript Client Library into Chrome App

So it's easy to load javascript client library in HTML. I'm talking about this one:

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

You just load it using,

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

Then you can use it..

function checkAuth() {
        gapi.auth.authorize(
          {
            'client_id': CLIENT_ID,
            'scope': SCOPES.join(' '),
            'immediate': true
          }, handleAuthResult);
      }

      function handleAuthResult(authResult) {
        var authorizeDiv = document.getElementById('authorize-div');
        if (authResult && !authResult.error) {
          // Hide auth UI, then load client library.
          authorizeDiv.style.display = 'none';
          doSomething();
        } else {
          // Show auth UI, allowing the user to initiate authorization by
          // clicking authorize button.
          authorizeDiv.style.display = 'inline';
        }
      }

Now, my question:

How do I do this in Chrome App? How do I load the JS client libraries so I can use it in Chrome app.

Figured out a way to do this. Just add the API libraries in your permissions in manifest.json.

"permissions": ["https://www.googleapis.com/*"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM