基本上,我试图在我的callBack GET方法中从Facebook获取Access Token。以下是我的代码。
根本没有调用{p>getAccessToken
。什么是实施它的正确方法?
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');
});
});
答案 0 :(得分:4)
您不应该使用app.use
来接听电话。
你必须尝试做类似下面的事情。在内部接到电话时,另外要求获得令牌。
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.
});
});