-3

Okay this is probably a crazy question, but for some reason I can't for the life of me pass 'body' out of this nested function.

function getFacebookUserInfo(sender_psid) {
  request({
      "url": "https://graph.facebook.com/v2.6/" + sender_psid,
      "qs": {
        "fields": "first_name,last_name,profile_pic,gender",
        "access_token": PAGE_ACCESS_TOKEN
      }
    },
    function(error, response, body) {
      if (error) {
        console.log(error);
        return;
      }
      return (JSON.parse(body));
    });
}
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
Mike Baker
  • 31
  • 1
  • Think about where `return JSON.parse(body)` is returning too. How is it being called? – RobG Oct 25 '17 at 02:35

1 Answers1

1

You are trying to get a return value from a asynchronous function as far as I see. This doesn't work, you either return a promise and do something when the function resolves, or you pass a callback function to the query, which means you do whatever you wanted to do within

function ( error, response, body ) {}
Koenigsberg
  • 1,726
  • 1
  • 10
  • 22