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:
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
MySQL Alter Table Add Field Before or After a Field Already Present
How to Send Notification to Android from PHP
PHP Rename Array Keys in Multidimensional Array
How to Prevent PHP Files from Being Downloaded? and What Are Some Ways Someone Can Download Them
"Class Xxx Is Not a Valid Entity or Mapped Super Class" After Moving the Class in the Filesystem
How to Call a Python Script from PHP
Assets Not Referencing to Public Folder (Laravel)
Exclude Hidden Files from Scandir
PHP How to Get the Base Domain/Url
PHP MySQL_Real_Escape_String() -> Stripslashes() Leaving Multiple Slashes
Returning Header as Array Using Curl
How to Write to Error Log File in PHP
Check If All Values in Array Are the Same