Facebook Graph API 图片 - 获取带有.jpg的完整 URL



我可以通过访问用户id从FB访问我的用户图像,如下所示:
https://graph.facebook.com/<USER_ID>/picture

但是,为了使我的代码正常工作,我需要图像的真正路径,例如
http://profile.ak.fbcdn.net/hprofile-ak-snc6/******_**************_********_q.jpg

FBs 文档显示,通过添加?callback=foo我可以得到一个输出,但实际上它似乎不起作用。

任何关于使用graph apiuser id.jpg扩展名获取我的图像的完整路径的建议,谢谢。

回调用于 javascript 请求,

对于 php,请尝试在 url 中附加一个redirect=false

执行卷曲请求,

https://graph.facebook.com/shaverm/picture?redirect=false

如果你想在js中使用回调,

$.getJSON('https://graph.facebook.com/zuck/picture?callback=?',function (resp) {
    $('body').html(resp.data.url);
});​

演示

参考

*使用以下你永远不会得到错误的结果*

$URL='FB GRAPH API URL';
$headers = get_headers($URL, 1); // make link request and wait for redirection
    if(isset($headers['Location'])) {
      $URL = $headers['Location']; // this gets the new url
    }
    $url_arr = explode ('/',$URL);
    $ct = count($url_arr);
    $name = $url_arr[$ct-1];
    $name_div = explode('.', $name);
    $ct_dot = count($name_div);
    $img_type = $name_div[$ct_dot -1];
    $pos = strrpos($img_type, "&");//many time you got in url
    if($pos)
    {
        $pieces = explode("&", $img_type);
        $img_type = $pieces[0];
    }
    $imagename = imgnameyouwant'.'.$img_type;
    $content = file_get_contents($URL);
    file_put_contents("fbscrapedimages/$imagename", $content);

最新更新