Javascript Node.js https.get()未返回Facebook访问令牌

Javascript Node.js https.get()未返回Facebook访问令牌,javascript,facebook,node.js,facebook-graph-api,Javascript,Facebook,Node.js,Facebook Graph Api,我正在尝试在node.js应用程序中设置Facebook登录流,但由于某些原因,当我使用node的https.get()时,无法从Facebook API获取访问令牌返回。但是,当我使用curl时,我可以获得访问令牌,所以我不确定哪个节点做得不同。相关代码: var express = require("express"); var https = require("https"); var app = express(); app.route("/") .all(function(

我正在尝试在node.js应用程序中设置Facebook登录流,但由于某些原因,当我使用node的https.get()时,无法从Facebook API获取访问令牌返回。但是,当我使用curl时,我可以获得访问令牌,所以我不确定哪个节点做得不同。相关代码:

var express = require("express");
var https = require("https");

var app = express();

app.route("/")
    .all(function(req, res, next)
    {
        res.sendfile("index.html");
    });

app.route("/login")
    .get(function(req, res, next)
    {
        res.redirect("https://www.facebook.com/dialog/oauth?" +
            "client_id={my_client_id}&" +
            "redirect_uri=http://localhost:3000/auth");
    });

app.route("/auth")
    .get(function(req, res, next)
    {
        var code = req.query.code;
        https.get("https://graph.facebook.com/oauth/access_token?" + 
            "client_id={my_client_id}" +
            "&redirect_uri=http://localhost:3000/auth" +
            "&client_secret={my_client_secret}" +
            "&code=" + code,
            function(token_response)
            {
                // token_response doesn't contain token...
                res.sendfile("logged_in.html");
            }
        ).on("error", function(e) {
            console.log("error: " + e.message);
        });
    });

var server = app.listen("3000", function()
{
    console.log("listening on port %d...", server.address().port);
});

token\u response
最终成为一个似乎与访问令牌无关的巨大对象。Facebook开发者文档说我应该回去:
access\u token={access token}&expires={seconds til expire}
这正是我使用curl时得到的,但不是node。

有点晚了。但你解决过这个问题吗

您似乎没有正确处理HTTPS响应


那么,
token\u response
对象包含什么呢?@Tobi它似乎有很多关于请求的数据,这些数据似乎在一次又一次地重复。我尝试创建一个函数,在所有属性中循环寻找一个名为“access\u token”的函数,但它找不到oneThanks!我最终弄明白了,并且做了你在这里所做的。数据事件修复了它
https.get("https://graph.facebook.com/oauth/access_token?" + 
        "client_id={my_client_id}" +
        "&redirect_uri=http://localhost:3000/auth" +
        "&client_secret={my_client_secret}" +
        "&code=" + code,
        function(res)
        {
            res.on('data', function(chunk) {
                console.log(chunk);
            });
        }
    )