javascript - How to extract data from url fetch response -
i implemented fetch method using google script , returns me following log:
[16-06-10 14:06:03:942 eest] { "accesstoken": "data", "userid": 3096, "created": "2016-06-10t05:06:03.799-06:00" }
does know how can extract value accesstoken
?
here gs code:
var url = "https://example.com" var payload = { 'username' : "user", 'password' : "pass", } var options = { 'method' : 'post', 'payload': json.stringify(payload), }; var urlresponse = urlfetchapp.fetch(url, options); logger.log(urlresponse); //this returns me log shown above
basically want add "data" value accesstoken
variable getdata
.
i think if variable urlresponse object return string value. should try that:
var data = json.parse(urlresponse.getcontenttext()); logger.log(data.accesstoken);
Comments
Post a Comment