I'm using the DracoBlue node-facebook-client and passport.js to authenticate a user into my app, then check if they are a member of a specific group.
I retrieve the users profile and access token then using the facebook_client try to get a session with the access token.
I'm not sure if the session being created properly because when I try using the method graphCall it throws the following error:
"500 TypeError: Object function (cb) { var session = new FacebookSession(self, access_token); cb(session); } has no method 'graphCall'"
A further source of information is found here.
Although not a php question. This is a node.js port of the php facebook client api so someone who uses that may have had the same problem.
Any help is greatly appreciated.
Thanks.
/* get the facebook client using ID and secret */
var facebook_client = new FacebookClient(
clientID, // configure like your fb app page states
clientSecret, // configure like your fb app page states
{
"timeout": 10000 // modify the global timeout for facebook calls (Default: 10000)
}
);
/*
* Define the facebook stragety
*/
passport.use(new FacebookStrategy({
clientID: clientID,
clientSecret: clientSecret,
callbackURL: "http://localhost:3000/auth/facebook/callback",
scope: 'user_groups' //Ask user to access their groups. Used for finding whether user is member of group
},
function(accessToken, refreshToken, profile, done) {
console.log('accessToken: ' + accessToken);
console.log('facebook_client: ' + facebook_client);
var facebook_session = facebook_client.getSessionByAccessToken(accessToken);
console.log('facebook_session: ' + facebook_session);
facebook_session.graphCall('/me?fields=groups')(function(result){
if(!result.error)
{
console.log(groups.data);
}
else
{
console.log('Error: ' + result.error.message);
console.log('nane: ' + result.data);
}
});
console.log('profile.groups ' + profile.user_groups);
console.log('accessToken ' + accessToken);
console.log('refreshToken ' + refreshToken);
done(null, profile);
}
));
The syntax was incorrect.
To retrieve the session I had to write the following:
facebook_client.getSessionByAccessToken(accessToken)(function(session){
});
I'm relatively new to node.js and keep forgetting I need to use callbacks.