问题
Basically, I'm trying to get Access Token from Facebook in my callBack GET method. Below is my code.
getAccessToken is not called at all. What's the right way to implement it?
app.get('/fbcallback', function(req, res) {
var code = req.query.code;
var getAccessToken = 'https://graph.facebook.com/v2.12/oauth/access_token?'+
'client_id='+client_id+
'&redirect_uri='+redirect_uri+
'&client_secret='+client_secret+
'&code='+code;
app.use(getAccessToken, function(req, res) {
console.log('Token Call');
});
});
回答1:
You should not use app.use inside get the call.
You must be trying to do something like below. Inside get call make another get call for getting token.
var request = require('request');
app.get('/fbcallback', function (req, res) {
var code = req.query.code;
var getAccessToken = 'https://graph.facebook.com/v2.12/oauth/access_token?' +
'client_id=' + client_id +
'&redirect_uri=' + redirect_uri +
'&client_secret=' + client_secret +
'&code=' + code;
request(getAccessToken, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
});
来源:https://stackoverflow.com/questions/49318921/how-to-make-get-request-inside-a-get-request-in-nodejs-using-express