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

Était-ce utile?

La 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");

Autres conseils

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";
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top