- This topic has 0 replies, 1 voice, and was last updated 11 years, 9 months ago by CorsairTwo.
-
AuthorPosts
-
CorsairTwoMemberI am using Google Fusion Tables for the backend database for my application. I can easily issue select statements using AJAX and the data is returned in an array that I can easily manipulate. Whenever I try to do an INSERT or UPDATE I get a 501 error that says it is not recognizing the command as a POST. Here is a copy of the code that I am using:
function RegisterUserData() {var clientId = ‘xxxxxxx’;
var apiKey = ‘xxxxxx’;var scopes = ‘https://www.googleapis.com/auth/fusiontables’;
var tableId = ‘xxxxxxxxxx’;var UserName = ‘xxxxx’;
var EmailAddress = ‘xxxxxxx’;
// i have substituted the real values with placeholders for this explanation// create the query
var query = “INSERT INTO ‘” + tableId + “‘ (‘UserName’, ‘UserEmail’, ‘Date’) “;
query = query + “VALUES (‘” + UserName + “‘, ‘” + EmailAddress + “‘” + Date() + “‘)”;var encodedQuery = encodeURIComponent(query);
// Construct the URL
var url = [‘https://www.googleapis.com/fusiontables/v1/query’%5D;
url.push(‘?sql=’ + encodedQuery);
url.push(‘&key= ‘ + apiKey);
url.push(‘&callback=?’);/ Send the JSONP request using jQuery
$.ajax({
url: url.join(”),
type:’POST’,
dataType: ‘jsonp’,
success: function (data) {
var rows = data[rows];}
});
}This is the same code used to fetch data with the “type: ‘GET’ and it work perfectly. I end up with an arrray “rows” that contains the records.
I believe the issue to be an authorization issue. I have found JavaScript code for using the OAuth 2.0 functions and that code works from web pages. Here is that code:
// Run OAuth 2.0 authorization.
function auth(immediate) {
gapi.auth.authorize({
client_id: clientId,
scope: scopes,
immediate: immediate
}, handleAuthResult);
}// Handle the results of the OAuth 2.0 flow.
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById(‘authorize-button’);
var createTableButton = document.getElementById(‘create-table’);
if (authResult) {
authorizeButton.disabled = true;
createTableButton.disabled = false;
} else {
authorizeButton.disabled = false;
authorizeButton.onclick = function() { auth(false); return false; };
}
}I don’t know how to translate that into something that works with MobiOne. I get errors on the ” gapi.auth.authorize” code
Can you point me to a reference on what code to use or can you translate the above into “Mobi-speak”?
David -
AuthorPosts