如何使用Express在NodeJS中的GET请求中发出GET请求

阿尼鲁德

基本上,我试图在我的CallBack GET方法中从Facebook获取访问令牌。下面是我的代码。

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');

   });


});
拉胡尔·沙玛(Rahul Sharma)

您不应该app.use在Inside内使用该呼叫。

您必须尝试执行以下操作。在get调用内部,进行另一个get调用以获取令牌。

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.
    });
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章