我的解决方案:
<?php
$ch = curl_init("http://graph.facebook.com/$id/picture?width=350&height=500&redirect=false");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // Mean 5 seconds
$content = curl_exec($ch);
$data = json_decode($content, true);
curl_close($ch);
var_dump($data["data"]["url"]);
PHP 与 file_get_contents()
<?php
$content = file_get_contents("http://graph.facebook.com/$id/picture?width=350&height=500&redirect=false");
$data = json_decode($content, true);
var_dump($data["data"]["url"]);
带有 jQuery 的 JavaScript
var url = "http://graph.facebook.com/ID/picture?width=350&height=500&redirect=false";
$.get(url,function(resp) {
alert(resp.data.url);
});
编辑
您是否尝试删除“&redirect=false”
"https://graph.facebook.com/$id/picture?width=350&height=500"
redirect to
"https://fbcdn-profile-a.akamaihd.net/hprofil[...]"
所以你可以这样做:
<?php
$url = "https://graph.facebook.com/$id/picture?width=350&height=500";
$data = file_get_contents($url);
$fp = fopen("img$id.jpg","wb");
if (!$fp) exit;
fwrite($fp, $data);
fclose($fp);
了解有关图片图表的更多信息