Problems using the goo.gl API from google apps script -
i'm trying query goo.gl api inside google apps script. problem i'm seeing following error message:
request failed https://www.googleapis.com/urlshortener/v1/url?key=aixxxxxxxxxxxxxxxxxxxxxlmgjqw returned code 400. server response: { "error": { "errors": [ { "domain": "global", "reason": "parseerror", "message": "this api not support parsing form-encoded input." } ], "code": 400, "message": "this api not support parsing form-encoded input." } } (line 28) the message comes when try actual request @ urlfetchapp.fetch(post_url, options);.
here's actual coding i'm using in google apps script.
function minifygoogl(longurl) { var post_url = 'https://www.googleapis.com/urlshortener/v1/url'; var apikey = userproperties.getproperty('googl_api_key'); if(!apikey){ var apikey = scriptproperties.getproperty('googl_api_key'); } if(apikey){ post_url += '?key=' + apikey; } var payload = utilities.jsonstringify({'longurl': longurl }); var options = { 'method' : 'post', 'headers' : { 'content-type' : 'application/json' }, 'payload' : payload }; try{ var response = urlfetchapp.fetch(post_url, options); }catch(e){ if(e.message){ throw e.message; } } var responsejson = response.getas('json'); } function testminifygoogl(){ minifygoogl('http://eduardo.cereto.net'); }
the documentation says contenttype defaults 'application/x-www-form-urlencoded'.
perhaps try setting content-type contenttype argument rather inserting content-type header manually?
Comments
Post a Comment