Node.js https.get()不返回Facebook访问令牌
我试图在我的node.js应用程序中设置一个Facebookloginstream,但由于某种原因,当我使用节点的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_response
最终成为一个巨大的对象,似乎没有任何相关的访问令牌。 Facebook开发者文档说我应该回来: access_token={access-token}&expires={seconds-til-expiration}
这正是我使用curl时得到的,而不是节点。
有点晚了 但是你有没有解决这个问题?
看起来你错误地处理了HTTPS响应。
http://nodejs.org/api/https.html
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); }); } )
- Node.JS中的Facebook OAuth:存储访问令牌
- passport-facebook-token返回InternalOAuthError:validation令牌时无法获取用户configuration文件
- PassportJS会话混合起来
- Express.js + Facebook
- validationFacebook X-Hub-Signature
- 尝试通过node.js http POST到“graph.facebook.com”时,发生“读取ECONNRESET”错误
- node.js表示app.get和app.post
- node.js – facebook连接 – 最新的lib
- 如何从Node.js访问Facebook用户数据?