【问题标题】:How to post on Facebook with Node.js?如何使用 Node.js 在 Facebook 上发帖?
【发布时间】:2013-12-24 03:18:02
【问题描述】:

我刚开始使用 Node.js 以及它的模块导出和通行证。在为 Facebook 设置登录后,我被困了几个小时如何在应用程序内的墙上发帖。我已经在 Facebook 开发者上注册了应用程序以获取它的 App ID 和 App Secret。我还将它注册到本地主机。我现在如何在 Facebook 上发帖?

这是我目前的代码:

var passport = require('passport')
  , FacebookStrategy = require('passport-facebook').Strategy;

passport.use(new FacebookStrategy({
    clientID:   APP_ID,
    clientSecret:   APP_SECRET,
    callbackURL: "http://localhost:3000/"
  },
  function(accessToken, refreshToken, profile, done) {
    /*
    User.findOrCreate(..., function(err, user) {
      if (err) { return done(err); }
      done(null, user);
    });
    */
  }
));


var express = require('express');
var app = express();

app.get('/', function(req, res){
  res.send('hello world <a href="/auth/facebook">Login with Facebook</a>');
});

app.listen(3000);


// Redirect the user to Facebook for authentication.  When complete,
// Facebook will redirect the user back to the application at
//     /auth/facebook/callback
app.get('/auth/facebook', passport.authenticate('facebook'));

// Facebook will redirect the user to this URL after approval.  Finish the
// authentication process by attempting to obtain an access token.  If
// access was granted, the user will be logged in.  Otherwise,
// authentication has failed.
app.get('/auth/facebook/callback', 
  passport.authenticate('facebook', { successRedirect: '/',
                                      failureRedirect: '/login' }
                        )
);

登录后,我的 URL 如下所示:

http://localhost:3000/?code=AQAbQE...

这个代码变量是token吧?

【问题讨论】:

    标签: javascript facebook node.js


    【解决方案1】:

    我曾经使用过 fb 模块,它真的很容易使用。非常直截了当。 npm install fb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多