Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.93k stars 596 forks source link

Is it possible to add profilePicture to getUserInfo()? #773

Open ghost opened 4 years ago

ghost commented 4 years ago

Now there is only thumbSrc in getUserInfo(), which is a very small profile picture (32x32px), I think adding profilePicture can be useful.

Madek1 commented 4 years ago

If you really need this feature, you can use this code I know it isn't good solution, but i couldn't find another way to resolve your problem. i'm not sure how defaultFuncs works

"use strict";

var utils = require("facebook-chat-api/utils");
var log = require("npmlog");

module.exports = function(defaultFuncs, api, ctx) {
  return function getUserPhoto(id, callback) {
    if (!callback) {
      throw { error: "getUserPhoto: need callback" };
    }

    defaultFuncs
      .get("https://graph.facebook.com/v5.0/" + id + "/picture?type=large&width=4096")
      .then(function(resData) {
        if (resData.error) {
          throw resData;
        }

        callback(null, {userID: id, photoUrl: resData.request.href});
      })
      .catch(function(err) {
        log.error("getUserPhoto", err);
        return callback(err);
      });
  };
};

This function returns object with 2 params (userID, photoUrl). photoURL gives you original photo