Monday 11 April 2016

[Beginner question] - How can I call and return the token from another function?

Hi guys,Sorry but another beginner question here.I have the tokenRefresh function which works and can output the access_token correctly.What I want to do is have other functions call the tokenRequest function to get the latest token.I've tried calling but it doesn't seem to work - can someone please help?var request = require('request'), googleConfig = require('./config/google.json'), brandsConfig = require('./config/brands.json'); requestMe(); function tokenRequest() { var payload = { client_id : googleConfig.client_id, client_secret : googleConfig.client_secret, grant_type : googleConfig.grant_type, content_type : googleConfig.content_type, refresh_token : googleConfig.refresh_token }; var url = "http://ift.tt/IlrJjr"; var options = { method : 'post', muteHttpExceptions : false, body : payload, json : true, url : url }; request.post(url, { form: payload }, function(error, response, body) { var parsed = JSON.parse(body); var access_token = parsed.access_token; //console.log(access_token) return(access_token); }); } function requestMe(){ var access_token = tokenRequest(); console.log(access_token); }

Submitted April 11, 2016 at 10:22PM by turtleattacks

No comments:

Post a Comment