Answer the question
In order to leave comments, you need to log in
How to download user avatar from graph.facebook?
Good afternoon,
the site organizes user registration through social networks, including facebook.
To upload the facebook user avatar to the site, I use the URL:
graph.facebook.com/100001039666189/picture?width=5...
from the data object I get the cdn url containing a link to the avatar
https://scontent.xx.fbcdn.net/v/ t1.0-1/p720x720/11...
any attempt to download a file via curl or file_get_contents fails. As I understand it, the response from the server is 403
An example of one of the attempts to download an image:
$ID = '100001039666189';
$ch = curl_init("http://graph.facebook.com/'.$ID.'/picture?width=500&height=500&redirect=false");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$content = curl_exec($ch);
$data = json_decode($content, true);
curl_close($ch);
$get = file_get_contents($data['data']['url']);
$f = fopen('fb_'.$ID.'.jpg', 'w+');
fputs($f, $get);
fclose($f);
Answer the question
In order to leave comments, you need to log in
Some kind of absurdity, instead of immediately getting a picture, first you get json with a link, and then you download it with one function, then you write another one to a file O_O
$ID = '100001039666189';
$url= "http://graph.facebook.com/{$ID}/picture?width=500&height=500";
$data = file_get_contents($url);
file_put_contents('filename.filetpe', $data);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question