Is there any way to change the user's profile picture using the graph api?
I know you can't with the rest api (reference), but I could not find anything in the new graph api.
Go to “My apps” drop down in the top right corner and select “add a new app”. Choose a display name and a category and then “Create App ID”. Again get back to the same link developers.facebook.com/tools/explorer. You will see “Graph API Explorer” below “My Apps” in the top right corner.
From this documentation, choose any field you want from which you want to extract data such as “groups” or “pages” etc. Go to examples of codes after having selected these and then select “facebook graph api” and you will get hints on how to extract information.
The profile object is used within the Graph API to refer to the generic type that includes all of these other objects. The individual reference docs for each profile type should be used instead. When something has a profile, Graph API returns the fields for that object.
From “Graph API Explorer” drop down, select your app. Then, select “Get Token”. From this drop down, select “Get User Access Token”. Select permissions from the menu that appears and then select “Get Access Token.”. Go to link developers.facebook.com/tools/accesstoken. Select “Debug” corresponding to “User Token”. Go to “Extend Token Access”.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With