google maps - Updating Fusion Table through Javascript -
so i've been trying update fusion table through google fusion table api specified here:
https://developers.google.com/fusiontables/docs/v1/using#updaterow
and i've run snag authentication believe. i've been trying authenticate using oauth 2.0.
so first problem stands. how i'm building thing. first populate array of items want update information fusion table:
$(document).ready(function () { $.ajax({ cache: false, async: true, type: "get", datatype: "json", url: "https://www.googleapis.com/fusiontables/v1/query?sql=select rowid, threepartaddress, latitude, longitude <table name> latitude != '0' , longitude != '0' limit 100&key=<key name>", contenttype: "application/json;charset=utf-8", success: function (m) { if (m != null) { meetings = m; } }, error: function (e) { console.log(e.statustext); } }); });
the meetings variable stores intermediate table data want update with. geocode address pulled , want convert , store coordinates. geocoding api (which listens first 10 requests issue guess entirely).
function processlatlng(geocoder, i, rows) { geocoder.geocode({ 'address': rows[i][1] }, function (results, status) { if (status == google.maps.geocoderstatus.ok) { // fire query update our lat lng rows[i][2] = results[0].geometry.location.lat(); rows[i][3] = results[0].geometry.location.lng(); } else { console.log('error geo: ' + status); } } ); }
now here's i'm having problems. go off , fetch login token in oauth. pulled question on stackoverflow. seems work once. client id google :
var google_auth_url = "https://accounts.google.com/o/oauth2/auth"; var google_client_id = "blahblah.apps.googleusercontent.com"; var plus_me_scope = "https://www.googleapis.com/auth/plus.me"; var button = document.createelement("button"); button.innertext = "authenticate google"; button.onclick = function() { var req = { "authurl" : google_auth_url, "clientid" : google_client_id, "scopes" : [ plus_me_scope ], }; oauth2.login(req, function(token) { logintoken = token; }, function(error) { alert("error:\n" + error); }); }; document.body.appendchild(button);
i @ latitude , longitude in function , update meetings. start looping on array. start building query update table name fire post request thing going.
function uploadlatlngs() { (row = 1; // first row (0) column headers meetings.rows.length > row; row++) { var lat = meetings.rows[row][2]; var lng = meetings.rows[row][3]; if (lat != '' && lat != null && lng != '' && lng != null && !(lat == 0 && lng == 0)) { var data = "?sql=update <table name> set latitude = " + lat + ", longitude = " + lng + " rowid = '" + meetings.rows[row][0] + "'"; var url = "https://www.google.com/fusiontables/v1/query/" + data; //"&access_token=" + logintoken; $.ajax({ type: "post", contenttype: "application/json", url: url, beforesend: function (xhr) { xhr.setrequestheader("authorization", "bearer " + logintoken); }, success: function run(data) { console.log(data); } }); } } }
when start firing these requests cors access error on every one.
options https://www.google.com/fusiontables/v1/query/?sql=update%<table name>,%20longitude%20=%20-77.09161899999998%20where%20rowid%20=%20%2725%27 405 (method not allowed) jquery-1.4.2.min.js:128 options https://www.google.com/fusiontables/v1/query/?sql=update%20<table name>,%20longitude%20=%20-77.09161899999998%20where%20rowid%20=%20%2725%27 no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:53104' therefore not allowed access.
i've ever seen work once , seems happen if use the: https://developers.google.com/oauthplayground/ generate access token. can't seem working own client id.
what missing here? here's "sort of" view of google dev console:
client id web application client id xxxx email address xxx client secret xxxx redirect uris http://localhost:53104/googlemapstest/testing/oauthwindow.html javascript origins http://localhost:53104
oauthwindow window i'm authorizing from
Comments
Post a Comment