Reputation: 885
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
Upvotes: 0
Views: 8571
Reputation: 191
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";
}
Upvotes: 0
Reputation: 365
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");
Upvotes: 1
Reputation: 15686
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");
Upvotes: 6