简体   繁体   English

用于node.js范围参数的facebook-node-sdk?

[英]facebook-node-sdk for node.js scope parameter?

https://github.com/amachang/facebook-node-sdk decided to use this module to build my facebook integrated login for node.js following the example with express: https://github.com/amachang/facebook-node-sdk决定使用此模块为node.js建立我的facebook集成登录,遵循以下示例:

var express = require('express');

var Facebook = require('facebook-node-sdk'); var Facebook = require('facebook-node-sdk');

var app = express.createServer();
app.configure(function () {
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({ secret: 'foo bar' }));
  app.use(Facebook.middleware({ appId: 'YOUR_APP_ID', secret: 'YOUR_APP_SECRET' }));
});

app.get('/', Facebook.loginRequired(), function (req, res) {
  req.facebook.api('/me', function(err, user) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello, ' + user.name + '!');
  });
});

how to add additional permissions like "email"? 如何添加“电子邮件”等附加权限?

Take a look at the method getLoginUrl in the Facebook Node SDK. 看一下Facebook Node SDK中的getLoginUrl方法。 You can provide a scope parameter here to specify the email permission. 您可以在此处提供scope参数以指定email权限。 See Permissions for a list of available permissions. 有关可用权限的列表,请参阅权限

app.get('/', Facebook.loginRequired({scope: 'email'}), function (req, res) {
      /*-----*/
});

hmm You don't need to edit this file :) all you have to do is add scope to your config, like this: 嗯你不需要编辑这个文件:)所有你要做的就是为你的配置添加范围,如下所示:

app.use(Facebook.middleware({ appId: 'YOUR_APP_ID', secret: 'YOUR_APP_SECRET', scope 'YOUR_SCOPE' }))

this config is then passed to getLoginUrl function 然后将此配置传递给getLoginUrl函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM