1

我编写了通过图形 API 获取 facebook 详细信息的代码。我收到了来自 facebook API 的响应,但我无法将这些响应呈现给我的 DUST 模板。

下面的代码用于渲染 DUST 模板。

res.render('listme', me);

我收到以下错误:

  c:\Users\rksbala\node_modules\facebook-sdk\example\connect.js:53
              res.render('listme', me);
                  ^
    TypeError: Object #<ServerResponse> has no method 'render'
        at c:\Users\bradha\node_modules\facebook-sdk\example\connect.js:53:15
        at Facebook._graph (c:\Users\bradha\node_modules\facebook-sdk\lib\facebook.js:459:21)
        at IncomingMessage.Facebook._makeRequest.FacebookApiException.error_code (c:\Users\bradha\node_modules\facebook-sdk\lib\facebook.js:529:9)
        at IncomingMessage.EventEmitter.emit (events.js:115:20)
        at IncomingMessage._emitEnd (http.js:366:10)
        at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
        at CleartextStream.socketOnData [as ondata] (http.js:1366:20)
        at CleartextStream.CryptoStream._push (tls.js:492:27)
        at SecurePair.cycle (tls.js:846:20)
        at EncryptedStream.CryptoStream.write (tls.js:227:13)  

app.js 代码:

 var express = require('express')
          , routes = require('routes')
          , http = require('http')
          , dust = require('dustjs-linkedin')
          , cons = require('consolidate')
          , path = require('path')
          , connect = require('connect')
          , fbsdk = require('facebook-sdk');


        var port = 8000;

        connect()
          .use(connect.favicon())
          .use(connect.cookieParser())
          .use(connect.bodyParser())
          .use(connect.methodOverride())
          .use(fbsdk.facebook({
            appId  : 'XXXXXXXXXXXXXXXXXXX',
            secret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
          }))

          .use(function(req, res, next) {
            var model = {title: 'PayPal :: Add Credit Card'};
            if (req.facebook.getSession()) {

              // get my graph api information
              req.facebook.api('/me', function(me) {
                var model;              
                if (me.error) {
                  res.end('An api error occured, so probably you logged out. Refresh to try it again...');
                } else {                 
                  res.render('listme', me);
                 //console.log(res);
                }
              });

            } else {
              res.end('<a href="' + req.facebook.getLoginUrl() + '">Login</a>');
            } 
          })
          .listen(port);

        console.log('Listening for http requests on port ' + port);

请让我知道我犯了什么错误。

4

0 回答 0