Advertisement:

Author Topic: [Tip] Get users profile pictures from Facebook  (Read 1455 times)

nCo

  • Newbie
  • *
  • Posts: 2
[Tip] Get users profile pictures from Facebook
« on: September 12, 2014, 03:30:42 am »
If you use Facebook Connect plugin (1.4.1) and have a theme with profile pictures of registered users, you can use this to display their FB profile picture. It defaults to a standard image for users without FB or when something goes wrong.

In plugins/Facebook/index.php add this function under fbc_button function:

   function fbc_image($user, $width, $height, $default) {
        $manager = User::newInstance();
        $manager->dao->select('i_facebook_uid');
        $manager->dao->from( DB_TABLE_PREFIX.'t_facebook_connect' );
        $manager->dao->where( 'fk_i_user_id', $user );
        $result = $manager->dao->get();
      
      if($result->result()!=array()) {
            $row = $result->row();
         echo 'https://graph.facebook.com/' . $row['i_facebook_uid'] . '/picture?width=' . $width . '&height=' . $height;
      } else {
         echo $default;
        }
    }

In your theme php page use this syntax:

<?php fbc_image( osc_user_id(), *WIDTH OF IMAGE*, *HEIGHT OF IMAGE*, *PATH TO DEFAULT PICTURE*); ?>

Example:

<img src="<?php fbc_image( osc_user_id(), 200, 200, '/oc-content/themes/osclass/img/user_default.png'); ?>" />

luison99

  • Newbie
  • *
  • Posts: 7
Re: [Tip] Get users profile pictures from Facebook
« Reply #1 on: September 20, 2014, 09:12:36 pm »
Hi nCo,

your function works fine for connected users, but I want to show FB profile image for other users which may be not connected at this time (for instance users who have posted an item-post, using osc_item_user_id() instead of osc_user_id()), and then your function gets empty for some of them (users not connected). Do you know how to get FB i_facebook_uid even for not connected users? Should I change 't_facebook_connect' query table by another one??

Thanks a lot,
Luis.