0

Ich weiß, dass es einige Antworten gibt, aber es funktioniert nicht in meinem Fall. Mein Code funktioniert, indem grundlegende facebook user info bekommen aber ich möchte Benutzer friends.and erhalte ich user_friends Umfang definiert, aber nicht user_friends Daten bekommen dies ist mein Code EigentlichWie bekomme ich Facebook Freundesliste mit Pass js?

import express from 'express'; 
import path from 'path'; 
import webpack from 'webpack'; 
import webpackMiddleware from 'webpack-dev-middleware' 
import webpackHotMidleware from 'webpack-hot-middleware'; 
import bodyParser from 'body-parser'; 


    import webpackConfig from '../../webpack.config.dev'; 

    //Login Stuff 
    import passport from 'passport'; 
    import config from './Auth'; 
    const FacebookStrategy = require('passport-facebook').Strategy; 



    let app = express(); 
    app.use(bodyParser.json()); 
    app.use(express.static('public')) 


    const compiler = webpack(webpackConfig); 

    app.use(webpackMiddleware(compiler, { 
     hot: true, 
     publicPath: webpackConfig.output.publicPath, 
     noInfo: true 
    })); 

    app.use(webpackHotMidleware(compiler)); 

    //FacebookConfigStarts 
    passport.use(new FacebookStrategy({ 
      clientID: config.facebookAuth.clientID, 
      clientSecret: config.facebookAuth.clientSecret, 
      callbackURL: config.facebookAuth.callbackURL, 
      profileFields: ['id', 'displayName', 'photos', 'email'] 
     }, 
     function(accessToken, refreshToken, profile, done) { 


      console.log(profile) 


     } 
    )); 



    app.get('/auth/facebook', passport.authenticate('facebook',{ scope: ['email','user_friends','manage_pages'] })); 


    app.get('/auth/facebook/callback', 
     passport.authenticate('facebook', { successRedirect: '/profile', 
      failureRedirect: '/login' 

     })); 



    //FacebookConfigEnds 
    app.get('/*', (req, res) => { 
     res.sendFile(path.join(__dirname, '../../index.html')) 
    }); 


    app.listen(3000,() => { 
     console.log('Listening') 
    }); 
+0

Sie fragen nicht nach dem Feld. Plus: http://stackoverflow.com/q/23417356/1427878 – CBroe

Antwort

2

Dieser Code-Schnipsel auf meine Anwendung funktioniert

importFacebook = (user, accessToken, cb:() => void) => { 
    var options = { 
     host: 'graph.facebook.com', 
     port: 443, 
     path: '/v2.9/' + user.facebook.id + '/taggable_friends?access_token=' + accessToken, //apiPath example: '/me/friends' 
     method: 'GET' 
    }; 

    var buffer = ''; //this buffer will be populated with the chunks of the data received from facebook 
    var request = https.get(options, function (result) { 
     result.setEncoding('utf8'); 
     result.on('data', function (chunk) { 
      buffer += chunk; 
     }); 

     result.on('end', function() { 
      console.log(buffer); 
      cb(); 
     }); 
    }); 

    request.on('error', function (e) { 
     console.log('error from facebook.getFbData: ' + e.message) 
     cb(); 
    }); 

    request.end(); 
}; 
Verwandte Themen