Question

i'm using graph api to connect to facebook. now i want to get the users facebook avatar and store in my own server, so later user could change photo. I could get photo through url: http://graph.facebook.com/[userid]/picture, but how to restore it directly from facebook to my server? thanks

Was it helpful?

Solution

You should be able to use copy() to copy the image to your server.

Example:

copy("http://facebook/picture/url","/path/on/server/img.jpg");

OTHER TIPS

Look at

fopen("http://graph.facebook.com/[userid]/picture");

Or if it doesn't work, try:

file_get_contents("http://graph.facebook.com/[userid]/picture");

Something like this should work (assuming you have an access token or you can use a user_id without a token):

$file = 'http://graph.facebook.com/me/picture';
$newfile = 'users_picture.jpg';

if (!copy($file, $newfile)) {
    echo "failed to copy $file";
} else {
    echo "Copied Profile Picture";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top