2014-10-20 267 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

相關問題