2011-12-15 92 views
0

我要保存以.jpg的真實圖像的URL,這樣做,我想獲得真正的圖像的URL,但我有一個這樣的網址 - http://graph.facebook.com/543525921/picture如何獲取url http://graph.facebook.com/{ANYUSERID}/picture的提取圖片url?

此URL的真實圖像的URL是 https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/371089_543525921_1936288375_q.jpg

如何顯示真實圖像的URL總是當我給像「http://graph.facebook.com/anyuserid/picture」的網址與PHP?

我嘗試了很多,但我失敗了..如果有一個幫助我..謝謝你!

+1

對不起!我找到了答案!如果任何人有這樣的事情,這可能會幫助你 - http://stackoverflow.com/questions/3535222/get-facebook-real-profile-image-url – 2011-12-15 08:08:45

回答

0

剛剛遇到同樣的問題,這裏是我用來解決的代碼。

$url = 'http://graph.facebook.com/' . $userInfo['id'] . '/picture?type=large'; 

$headers = get_headers($url, 1); // make link request and wait for redirection 

if(isset($headers['Location'])) { 
    $url = $headers['Location']; // this gets the new url 
} else { 
    $url = false; 
} 

$targetPath = $_SERVER['DOCUMENT_ROOT'] . "/yourImagePath/"); 
$destFile = "yourFileName.jpg" 

if($url){ 
    if (copy($url, $targetPath.$destFile)) { 
    // file is now copied to your server do what ever you want here 
    } 
}