how to set a facebook profile picture using the graph api

Upload the picture to an existing album (or create a new one) using the Graph API. Will look something like this:

  $args = array('message' => 'Caption');
  $args['image'] = '@' . realpath("the_image.png");

  try {
    $data = $facebook->api('/'.$album_uid.'/photos', 'post', $args);
  }
  catch(Exception $e) {
    print "<pre>";
    print_r($e);
    print "</pre>";
  }

Then get the uploaded image via the Graph API and redirect to the image's link, add &makeprofile=1 to the querystring. The user will now be redirected to the profile image cropping page:

try {
  $pictue = $facebook->api('/'.$data['id']);
  header("Location: ".$pictue['link']."&makeprofile=1");
}
catch(Exception $e) {
  print "<pre>";
  print_r($e);
  print "</pre>";
}

PicBadges application (no longer available) is doing this job clearly. Just take a look at their app. Its pretty clear how they have implemented.

They are not directly uploading pictures to "Profile Pictures" album. Instead, they are uploading as usual to their auto generated album (on their app name) and then selecting the pic as "profile pic". However, this method involves redirection of users to page where they need to crop it before getting done.

Interesting implementation to note!


You can upload to the user's Profile Picture album using the Graph API but it appears that you cannot update the /me/picture value to set the users current profile image to the image you've uploaded.