Get Facebook real profile image URL

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.

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.

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

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.

Thanks

11
задан kire 20 August 2010 в 22:08
поделиться

2 ответа

Кир прав, но лучшим решением для вашего варианта использования будет следующее:

    // 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!
20
ответ дан 3 December 2019 в 02:40
поделиться

Вы можете получить это с помощью FQL:

select pic_square from user where uid=1489686594

возвращает:

[
  {
    "pic_square": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs356.snc4/41721_1489686594_527_q.jpg"
  }
]

Также вы можете просто улучшить вашу функцию, которая получает изображение по URL-адресу. Если вы используете curl , он может автоматически следовать за заголовками перенаправления.

7
ответ дан 3 December 2019 в 02:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: