Last active
February 6, 2018 04:49
-
-
Save Whoaa512/4596611 to your computer and use it in GitHub Desktop.
Meteor code to display user's facebook picture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); |
@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
guys is there a way to specify the size of the profile picture?