I have a question. I\'ve been trying to figure this out for the past 3 hours now, and I have no clue as to why this isn\'t working how i\'m expecting it to. Please know that
Async, async, async.
You cannot return the results of an asynchronous operation from the function. The function has long since returned before the asynchronous callback is called. So, the ONLY place to consume the result of your request.post()
is INSIDE the callback itself and by calling some other function from within that callback and passing the data to that other function.
var oauth = request.post(oauthOptions, function(e, r, body) {
// use the result here
// you cannot return it
// the function has already returned and this callback is being called
// by the networking infrastructure, not by your code
// you can call your own function here and pass it the async result
// or just insert the code here that processes the result
processAuth(body);
});
// this line of code here is executed BEFORE the callback above is called
// so, you cannot use the async result here
FYI, this is a very common learning issue for new node.js/Javascript developers. To code in node, you have to learn how to work with asynchronous callbacks like this.