How to query a Facebook user picture via Meteor's accounts-facebook?

前端 未结 2 777
一向
一向 2020-12-25 07:48

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(\"facebo         


        
相关标签:
2条回答
  • 2020-12-25 08:42

    if you want to get picture for facebook

    Accounts.onCreateUser(function(options, user) {
        if (typeof(user.services.facebook) != "undefined") {
            user.services.facebook.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
        }
        return user;
    });
    

    you can to add this helper function

    UI.registerHelper("getImageUser", function (userId) {
        var user= Meteor.users.findOne(userId);
        if (user.services)
        {
            if (user.services.facebook)
                return user.services.facebook.picture;
            if (user.services.twitter)
                return user.services.twitter.profile_image_url;
            if (user.services.google)
                return user.services.google.picture;
        }
        else
        {
            return "images/withOutPhoto.png";
        }
    });
    

    in your html

    <img src="{{getImageUser this._id}}" alt="...">
    
    0 讨论(0)
  • 2020-12-25 08:51

    Use this instead, you don't need an access token or anything special to get their profile picture, just their facebook user id.

    Accounts.onCreateUser(function(options, user) {
        if (options.profile) {
            options.profile.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
            user.profile = options.profile;
        }
        return user;
    });
    
    0 讨论(0)
提交回复
热议问题