1
votes

Has anyone had success in using the Gmail API's authorization in a Phonegap application? I found this (http://phonegap-tips.com/articles/google-api-oauth-with-phonegaps-inappbrowser.html) that describes using the generic Google API OAuth with Phonegap's inappbrowser plugin, but the newly released Gmail API does OAuth authorization differently, and I'm not sure how to get it to work with Phonegap.

Note: It does work when I try a web version of my app, but the button that brings up the authorization screen doesn't do anything in Phonegap..not sure why. I do have the appropriate Android credentials for the app in the Google Developer's Console.

UPDATE: Using OAuth's Phonegap SDK (found after registering your app here: https://oauth.io/), I am able to authenticate a Google Account. However, I am unsure how to then call Gmail API methods or correctly pass whatever authentication tokens from the OAuth SDK to any Gmail API code. Has anyone done this and can share their knowledge?

2
Can you elaborate/explain why you think "the newly release Gmail API does OAuth authorization differently"?Eric D
You just call gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);, which is different than the var authUrl = 'https://accounts.google.com/o/oauth2/auth?' + $.param({client_id: options.client_id, redirect_uri: options.redirect_uri, response_type: 'code', scope: options.scope});, the first having no url or uri redirect. I've tried calling window.open on the gapi call, similar to this (github.com/mdellanoce/google-api-oauth-phonegap/blob/v0.0.1/www/…), but it didnt workartis3n
Sorry that isn't a little cleanerartis3n

2 Answers

0
votes

I found a solution using the OAuthio Phonegap SDK. Then I can call the appropriate HTTPS requests from the Gmail API.

-1
votes

If you want to login your users via Google on iOS and Android, then use this new plugin I just created: https://github.com/EddyVerbruggen/cordova-plugin-googleplus

You will also receive the name and gender etc from the plugin. The plugin will also try SSO with any other Google apps installed on your device by using the Google+ SDK on both platforms.

Example on Android