Sunday, May 27, 2012

Facebook API - How do I get a facebook user"s profile image through the FB api (without requiring the user to Allow app)


I'm working on a CMS that fetches a user's profile image from their facebook url (ie, http://facebook.com/users_unique_url ). How can I accomplish this? Is there a faceboook API call that fetches a user's profile image url without the user needing to Allow the application?



Source: Tips4all

3 comments:

  1. Simply fetch the data through this url:

    http://graph.facebook.com/sarfraz.anees/picture

    Replace sarfraz.anees (my name) with name of the user you want to get the photo of.

    You can use the PHP's file_get_contents function to read that url and process the retrieved data.

    Resource:

    http://developers.facebook.com/docs/api

    Note: In php.ini, you need to make sure that openssl extension is enabled to use thefile_get_contents function of PHP to read that url.

    ReplyDelete
  2. To show:

    50x50 px:

    <img src="https://graph.facebook.com/<?= $fid ?>/picture">


    width: 200px

    <img src="https://graph.facebook.com/<?= $fid ?>/picture?type=large">


    To save:

    $img = file_get_contents('https://graph.facebook.com/'.$fid.'/picture?type=large');
    $file = dirname(__file__).'/avatar/'.$fid.'.jpg';
    file_put_contents($file, $img);


    Where $fid is your user id (or nickname) in facebook..

    ReplyDelete
  3. Is using

    https://graph.facebook.com/{user_id}/picture{?type=large}


    instead of

    https://graph.facebook.com/{user_username}/picture{?type=large}


    is safer?

    There are Facebook users which didn't set their username in Facebook.

    ReplyDelete