2014-10-20 195 views
-1

我用下面的代码保存的网址在Facebook的个人资料PIC通过facebbok如何通过Facebook提供的图片URL保存Facebook个人资料图片?

$data = file_get_contents('https://graph.facebook.com/[App-Scoped-ID]/picture?width=378&height=378&access_token=[Access-Token]'); 
$file = fopen('fblogo/fbphoto.jpg', 'w+'); 
fputs($file, $data); 
fclose($file); 

的图像保存在所需的地方,但它救了0字节意味着腐败提供,请让知道如何保存图像正常

回答

0

我用这个:

$image = json_decode(file_get_contents("https://graph.facebook.com/$data[id]/picture?width=800&height=600&redirect=false"),true); 
$image = file_get_contents($image['data']['url']); 
file_put_contents("desired_filename.jpg",$image); 
1

这看起来像从这个线程我的回答:Save facebook profile image using cURL

尝试向API调用添加redirect = false以获取图片的真实位置。如果还是不行,请尝试使用卷曲:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' . $app_scoped_id . '/picture?width=378&height=378&redirect=false&access_token=xxx'); 
$data = curl_exec($ch); 
$data = json_decode($data); 

这将让真正的网址,你可以使用另一个调用来获取图像:

curl_setopt($ch, CURLOPT_URL, $data->data->url); 
$data = curl_exec($ch); 
curl_close($ch); 

如果这也不起作用,请确保您的提供商支持CURL请求:)

+0

CURL答案效果很好。谢谢! – 2016-03-03 23:22:37

相关问题