如何使用Express在NodeJS中的GET请求中发出GET请求 [英] How to make GET request inside a GET request in NodeJS using Express

查看:256
本文介绍了如何使用Express在NodeJS中的GET请求中发出GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Basically, I'm trying to get Access Token from Facebook in my callBack GET method. Below is my code.

getAccessToken.实施它的正确方法是什么?

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

   });


});

推荐答案

您不应在呼叫中使用app.use.

您必须尝试执行以下操作.在get调用中进行另一个get调用以获取令牌.

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

这篇关于如何使用Express在NodeJS中的GET请求中发出GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆