获取Facebook真实资料图片网址

kir*_*ire 11 php api url facebook image

根据Facebook图形API,我们可以使用此示例请求用户个人资料图片(示例):

https://graph.facebook.com/1489686594/picture

我们不需要任何令牌,因为它是公共信息.

但上一个链接的真实图片网址是:http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs356.snc4/41721_1489686594_527_q.jpg

如果您在浏览器上键入第一个链接,它会将您重定向到第二个链接.

有没有办法通过知道第一个链接获得PHP的完整URL(第二个链接)?

我有一个函数从URL获取图像以将其存储在数据库中,但它只有在获得完整的图像URL时才有效.

谢谢

The*_*can 20

kire是对的,但对于您的用例更好的解决方案如下:

    // get the headers from the source without downloading anything
    // there will be a location header wich redirects to the actual url
    // you may want to put some error handling here in case the connection cant be established etc...
    // the second parameter gives us an assoziative array and not jut a sequential list so we can right away extract the location header
    $headers = get_headers('https://graph.facebook.com/1489686594/picture',1);
    // just a precaution, check whether the header isset...
    if(isset($headers['Location'])) {
        $url = $headers['Location']; // string
    } else {
        $url = false; // nothing there? .. weird, but okay!
    }
    // $url contains now the url of the profile picture, but be careful it might very well be only temporary! there's a reason why facebok does it this way ;)
    // the code is untested!
Run Code Online (Sandbox Code Playgroud)


ser*_*erg 7

您可以使用FQL获取它:

select pic_square from user where uid=1489686594
Run Code Online (Sandbox Code Playgroud)

收益:

[
  {
    "pic_square": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs356.snc4/41721_1489686594_527_q.jpg"
  }
]
Run Code Online (Sandbox Code Playgroud)

此外,您可以通过网址改善您的功能.如果您使用curl,它可以自动遵循重定向标头.

  • @kire有4种不同的图片可供选择,无论您需要哪种图片:http://developers.facebook.com/docs/reference/fql/user (3认同)