Adi Mabfalin Adi Mabfalin - 4 months ago 20
Javascript Question

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.

Answer

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

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