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
Asked
Active
Viewed 8,303 times
3 Answers
6
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");

Brian Glaz
- 15,468
- 4
- 37
- 55
1
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");

j0k
- 22,600
- 28
- 79
- 90

Lucas Zardo
- 355
- 1
- 3
- 7
-
1You'll need to be sure to have [allow_url_fopen](http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen) enabled for that to work. – sachleen Jun 28 '12 at 18:25
0
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";
}

DanCarlyon
- 191
- 3
- 7