Facebook API/PHP - How to Change a User's Profile Image via Fb Graph API

Facebook API/PHP - Is it possible to change a user's profile image via FB Graph API?

No, And here's a comment from a guy at facebook:

This Is A A Facebook Developer!

The Original Link - you have to press show comments

How can I display the users profile pic using the facebook graph api?

Knowing the user id the URL for their profile picture is:-

http://graph.facebook.com/[UID]/picture

where in place of [UID] you place your $uid variable, and that URL can be passed to flash

Facebook API - How do I get a Facebook user's profile image through the Facebook API (without requiring the user to Allow the application)

Simply fetch the data through this URL:

http://graph.facebook.com/userid_here/picture

Replace userid_here with id of the user you want to get the photo of. You can also use HTTPS as well.

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 the OpenSSL extension is enabled to use thefile_get_contents function of PHP to read that URL.

Saving User's Profile Picture from facebook API - PHP SDK V.5

So i found the solution myself and decided to answer so that if that can help someone else facing the same problem.

We need to pass a few parameters to the file_get_contents() function

$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$profile_picture = @file_get_contents($profile_picture, false, stream_context_create($arrContextOptions));
// Use @ to silent the error if user doesn't have any profile picture uploaded

Now the $profile_picture has the picture, we can save it anywhere in the following way.

$path = 'path/to/img';  //E.g assets/images/mypic.jpg

file_put_contents($path, $profile_picture);

That's all :-)

How to get a Facebook user's profile picture in php

To show image in page

<img src="//graph.facebook.com/{{fid}}/picture">

To save

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

Facebook Graph API

http://graph.facebook.com/abdulla.nilam/picture

how to save facebook profile picture using php graph Api

There is a pretty easy option for this:

$url = 'http://graph.facebook.com/shashankvaishnav/picture';
$data = file_get_contents($url);
$fileName = 'fb_profilepic.jpg';
$file = fopen($fileName, 'w+');
fputs($file, $data);
fclose($file);

You don´t even need anything else then.

Or if file_get_contents is disabled (usually it isn´t), this should also work:

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://graph.facebook.com/shashankvaishnav/picture');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$fileName = 'fb_profilepic.jpg';
$file = fopen($fileName, 'w+');
fputs($file, $data);
fclose($file);

Edit: This is not possible anymore, since you can´t use the username for API calls anymore. You have to use an (App Scoped) ID after authorizing a User with the Facebook API instead of the username.



Related Topics



Leave a reply



Submit