Authenticate to query a Fusion Table using Google Apps Script -


i member of google apps domain , trying use code examples query fusion table keep getting following error:

{   "error": {     "errors": [       {       "domain": "global",       "reason": "required",       "message": "login required",       "locationtype": "header",       "location": "authorization"       }     ],     "code": 401,     "message": "login required"   } } 

here code using:

function myfunction() {  //fusion table   var constructor = 'https://www.googleapis.com/fusiontables/v2/query?sql=';   var fusiontableid = '1pjk********uy5l';   var fusiontableapikey = 'aiza********agv8';  //  browser api key   var fusiontablequery = 'select * ' + fusiontableid + '&key=' + fusiontableapikey;     var querystring = constructor + fusiontablequery;    var response = urlfetchapp.fetch(querystring);    var parsedresponse = json.parse(response.getcontenttext());    logger.log(parsedresponse);  } 

unfortunately, due domain settings, unable share of files people outside of our domain. have reviewed reference here unsure how adapt doing.

i can script work using sample string google confident code right:

https://www.googleapis.com/fusiontables/v2/query?sql=select * from%201kxvv0wqxhxhmscsduqr-0ebf0yet4m4xzvplkd4&key=aizasyam9ywcv7jpcthcjut8whojard7pwrofdq 

thank in advance.

you need pass authorization header in request, either access token or login auth. shown in link posted.

anyway, easier use fusion table advanced service. enable go resources > advanced google services > fusion tables api.

if still want call manually. @ least enable service , put fake code apps script can request oauth2 scope you. e.g.

function noneedtorun() //just trigger scope   fusiontables.query.sql('foo'); //although easier urlfetch`ing manually }  function myfunction() {   //...your same code   var querystring = constructor + fusiontablequery;    var response = urlfetchapp.fetch(querystring, {     headers: { //this you're missing         "authorization": "bearer " + scriptapp.getoauthtoken(),     }   });    var parsedresponse = json.parse(response.getcontenttext());    logger.log(parsedresponse); } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -