Skip to content

Instantly share code, notes, and snippets.

@Whoaa512
Last active February 6, 2018 04:49
Show Gist options
  • Save Whoaa512/4596611 to your computer and use it in GitHub Desktop.
Save Whoaa512/4596611 to your computer and use it in GitHub Desktop.
Meteor code to display user's facebook picture
Meteor.startup(function() {
Template.fb_pic.pic = function() {// helper function to display the pic on the page
var userProfile;
userProfile = Meteor.user().profile;
if(userProfile) { // logic to handle logged out state
return userProfile.picture;
}
};
});
var getFbPicture = function(accessToken) { // make async call to grab the picture from facebook
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; // return the picture's url
};
// during new account creation get user picture from Facebook and save it on user object
Accounts.onCreateUser(function(options, user) {
if(options.profile) {
options.profile.picture = getFbPicture(user.services.facebook.accessToken);
user.profile = options.profile; // We still want the default 'profile' behavior.
}
return user;
});
@berkaytheunicorn
Copy link

guys is there a way to specify the size of the profile picture?

@erperejildo
Copy link

@berkaey, you could use this url http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment