I’m working on a mobile app using PhoneGap and Sencha Touch. I need to build functionality that connects to Google Drive and allows me to create and modify Google Fusion Tables directly from the app.
I have a working JavaScript solution that works perfectly in my local development environment. However, when I build the app and test it on my Android device, the authentication process fails completely. The Google OAuth authorization popup doesn’t show up even though my Gmail account is already logged in on the device.
Here’s a simplified version of my current implementation:
var appConfig = {
clientKey: 'your-client-id-here.apps.googleusercontent.com',
secretKey: 'your-secret-key',
apiToken: 'your-api-key',
permissions: 'https://www.googleapis.com/auth/fusiontables'
};
function initializeApp() {
gapi.client.setApiKey(appConfig.apiToken);
document.getElementById('btn-create').onclick = buildTable;
document.getElementById('btn-add').onclick = addRecord;
setTimeout(function() { authenticate(true); }, 100);
}
function authenticate(skipPrompt) {
gapi.auth.authorize({
client_id: appConfig.clientKey,
scope: appConfig.permissions,
immediate: skipPrompt
}, processAuthResponse);
}
function processAuthResponse(result) {
var authBtn = document.getElementById('auth-btn');
var createBtn = document.getElementById('btn-create');
if (result && result.access_token) {
authBtn.disabled = true;
createBtn.disabled = false;
} else {
authBtn.disabled = false;
authBtn.onclick = function() { authenticate(false); };
}
}
function buildTable() {
var tableSpec = {
name: "UserData",
columns: [
{ name: "Username", type: "STRING" },
{ name: "Score", type: "NUMBER" }
],
isExportable: true
};
executeRequest({
path: '/fusiontables/v1/tables',
body: JSON.stringify(tableSpec),
method: 'POST'
}, handleTableCreation);
}
What’s the best approach to make Google API authentication work properly in a PhoneGap mobile app? Are there specific configurations or plugins I need to handle OAuth flows on mobile devices?