Quantcast
Channel: Active questions tagged news-feed+facebook-graph-api+photo - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Manipulate photos url in facebook custom feed (graph API)

0
0

i'm trying to display some custom facebook feeds on my website from a facebook fan page. This is a summary sample of the php I used, and it works fine.

[...html code...]

// include the facebook sdk
require_once('resources/facebook-php-sdk-master/src/facebook.php');

// connect to app
$config = array();
$config['appId'] = 'MY_APP_ID';
$config['secret'] = 'MY_SECRET_CODE';
$config['fileUpload'] = false; // optional

// instantiate
$facebook = new Facebook($config);

// set page id
$pageid = "MY_PAGE_ID";

// access to the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");

[...html code...]

$i = 0;
foreach($pagefeed['data'] as $post) {
// check if post type is a photo and catch the various part of the graph
if ($post['type'] == 'photo') {
    //grab the thumbnail url in the graph           
    $picture_url = $post['picture'];
    //get true sized photo by manipulating its url  
    $picture_url_big = str_replace("s130x130/","", $picture_url);

    echo "<p><img class=\"img-icon\" src=\"" . $post['icon'] . "\"></p>";             
    echo "<h2 class=\"data-post\">" . date("j-n-Y", (strtotime($post['created_time']))) . "</h2>";
    //displaying the photo
    echo "<div class=\"img-thumb\"><a href=\"" . $post['link'] . "\" target=\"_blank\"><img src=\"" . $picture_url_big . "\"></div></a>";
    echo "<p class=\"manda-a-capo\"></p>";
        if (empty($post['story']) === false) {
            echo "<p>" . $post['story'] . "</p>";
        } elseif (empty($post['message']) === false) {
            echo "<p>" . $post['message'] . "</p>";
        }
            echo "<p><a href=\"" . $post['link'] . "\" target=\"_blank\"><u><b>Vedi foto</b></u></a></p>";
            echo "<p class=\"manda-a-capo\"></p>";
                if ($post['shares']['count'] != "") {
                    echo "<p class=\"manda-a-capo share-num\">" . $post['shares']['count'] . " condivisioni.</p>";
                }
}
$i++;
}

[...other code...]

The facebook graph contains only the thumb url of the photos, that is 130x130px. I discovered that some thumbs have an "/s130x130/" parameter in the url and, if you delete this parameter, you get the photo in its actual size. So this explains this part of code (as above):

//grab the thumbnail url in the graph           
$picture_url = $post['picture'];

//get true sized photo by manipulating its url  
$picture_url_big = str_replace("s130x130/","", $picture_url);

//then displaying the photo
echo "<div class=\"img-thumb\"><a href=\"" . $post['link'] . "\" target=\"_blank\"><img src=\"" . $picture_url_big . "\"></div></a>";

Unfortunately I noticed that not all photos from the page have this parameter and some of them have even a different url structure. So the final result is that I can reach only few photos in their actual size, others remain a broken link.

Is there a way to manipulate the url to get all the photos in their own actual size? Any advices?

Thanks.

P.S. Here's the php to view the fb graph:

<?php 
    echo "<pre>";
    print_r($pagefeed);
    echo "</pre>";
?>

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images