获取Facebook真实的个人资料图片URL [英] Get Facebook real profile image URL

查看:131
本文介绍了获取Facebook真实的个人资料图片URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Facebook图形API,我们可以通过这个(例如)请求用户个人资料图片:

According to Facebook graph API we can request a user profile picture with this (example):

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

我们不需要任何令牌因为它是一个公共信息。

We don't need any Token since it's a public information.

但是以前链接的真实图像URL是: http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs356.snc4/41721_1489686594_527_q.jpg

But the real image URL of the previous link is: http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs356.snc4/41721_1489686594_527_q.jpg

如果您在浏览器中输入第一个链接,它将重定向到第二个链接。

If you type the first link on your browser, it will redirect you to the second link.

有没有通过只知道第一个链接来获取完整的URL(第二个链接)的方法?

Is there any way to get the full URL (second link) with PHP, by only knowing the first link?

我有一个功能,可以从URL获取图像以将其存储在数据库,但它只有在获得完整的图像URL时才起作用。

I have a function that gets the image from a URL to store it in the database, but it does work only if it get the full image URL.

谢谢

推荐答案

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

kire is right, but a better solution for your use case would be the following:

    // 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!

这篇关于获取Facebook真实的个人资料图片URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆