I have an app using the Google JS API to log in the user with oauth and then get info from their gmail acct, etc. The app works fine on the web but is having trouble with Trigger.io (Android and iOS builds). The script is loaded via
<script src="https://apis.google.com/js/client.js?onload=ginit"></script>
and the ginit
function then calls the gapi
client loaded by client.js:
if (!!gapi) {
gapi.client.setApiKey(GoogleApp.apiKey);
}
On Android, gapi
exists, but gapi.client
somehow does not, causing an error.
On iOS, the library load works fine, but a subsequent call to gapi.auth.authorize
(which may cause a new window to open) causes a Webview error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed."
I am using both the Child Browser and Cross-domain ajax modules, but of course have no way to change the way the Google library implements calls. I put in code to ignore the error per this and similar, but still the auth doesn't work:
try {
gapi.auth.authorize({client_id: GoogleApp.clientId, scope: GoogleApp.scopes, response_type: 'token id_token', immediate: false, approval_prompt: 'force'}, gHandleAuthResult);
} catch (e) {
if (e.indexOf('NSURLErrorCancelled') === -1) { // iOS error on cancelled window, ignore
throw e;
}
}
Is there a better way to use the Google API from a Trigger.io app? Or an example of a Trigger.io app using the Google API?
My next issue will probably be with determining the js origin, which is already covered in another post but no answer yet. Thanks for any and all help!