I'm trying to get the authenticated Facebook user's profile picture, to use within a Meteor application. I've tried the following
Meteor.publish("facebook_avatar_url", function() {
return Meteor.users.find({_id: this.userId}, {fields: {
'services.facebook.id': 1,
'services.facebook.name': 1,
'services.facebook.gender': 1,
'services.facebook.picture': 1,
'services.facebook.picture.data': 1,
'services.facebook.picture.data.url': 1
}});
});
and it only returns the id, name, and gender. This seems to be what I want, and the recommended solution. Only problem is there's no data being returned regarding the user's picture.
I tried adding the following to server/server.js, at the suggestion of some other posts, but it a) doesn't seem to be the recommended approach, and b) doesn't seem to be doing anything. So, it seems to be a dead end, but somebody out there seems to think that it can be used to get the profile picture loaded up.
var getFbPicture;
Accounts.loginServiceConfiguration.remove({
service: "facebook"
});
Accounts.onCreateUser(function(options, user) {
if (options.profile) {
options.profile.picture = getFbPicture(user.services.facebook.accessToken);
user.profile = options.profile;
}
return user;
});
getFbPicture = function(accessToken) {
var result;
result = Meteor.http.get("https://graph.facebook.com/me", {
params: {
access_token: accessToken,
fields: 'picture'
}
});
if (result.error) {
throw result.error;
}
return result.data.picture.data.url;
};
So, I'm kinda unsure which direction to go at this point. Is this something that needs permissions set on the Facebook Graph API? Or on the Facebook Application? Do I have the syntax wrong in the publication function? Do I need to revisit the onCreateUser function?