Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing full size (851x315) timeline cover photo via graph api

I notice that when I access the timeline cover photo URL via the Graph API (using PHP) the photo returned is 720x266 instead of 851x315. Either using, <graph api url>/userId/?field=cover or by accessing the url in ['cover']['source'] of the json array returned when accessing <graph api url>/userID

I've been unable to find a way to retrieve the full size cover photo. Using firebug I can see Facebook load the full size 851x315 image, the only difference in the URL seems to be that the one returned by the API has 720x720 in the path,

What Facebook loads:

http://a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/xxxxxx_xxxxxxxxxxxxxxx_xxxxxxxxxx_n.jpg

What the Graph API returns

http://a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/s720x720/xxxxxx_xxxxxxxxxxxxxxx_xxxxxxxxxx_n.jpg

Is there a way way I can access that full size cover photo URL directly? I could parse the URL returned by the API to strip the 720x720 but I am hoping the is a more elegant way of obtaining the full size cover photo URL directly.

like image 633
Daniel Bigras Avatar asked Aug 11 '12 20:08

Daniel Bigras


3 Answers

Accessing full-size timeline cover photo of facebook user


In php , we can do the following. Its a small hack,and i dont gurantee that it will work for lifetime.

As you can see, there is a s720x720 in the returned photo url. Now we are going to replace that with l720 (L720). with the help of preg_replace() in php .


$coverphoto_url="https://a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/s720x720/xxxxxx_xxxxxxxxxxxxxxx_xxxxxxxxxx_n.jpg";

$coverphoto_url = preg_replace('/s720/i','l720',$coverphoto_url);

This will return,

https: //a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/l720x720/xxxxxx_xxxxxxxxxxxxxxx_xxxxxxxxxx_n.jpg


You can also do this with javascript.

coverphoto_url = coverphoto_url.replace(/s720/i, 'l720');

If you dont know how to retrieve coverphoto via graph API,then please read this question.

How to get a securl cover URL?

hope this helps someone :)

like image 73
Muhammed Aslam C Avatar answered Sep 27 '22 21:09

Muhammed Aslam C


The accepted answer is now broken with the new Facebook Graph API, I was able to get the high quality cover photo in JavaScript with this function:

FB.api("/hawaiianchimp?fields=cover", function(response){
        FB.api("/"+response.cover.id, function(response){
            var img_src = response.images[0].source;
        });
      });

This gets the cover photo ID and then does a second Graph API call to get the image source

like image 35
seantomburke Avatar answered Sep 27 '22 21:09

seantomburke


It appears in my testing that this part of the url is the crux of the matter: .../c0.0.851.315/...

So therefore perform a request like this:

$url = "https://graph.facebook.com/{$id}?fields=cover";

// // this points it to the actual banner, not the fullsized one 
$key_851 = 'c0.0.851.315';

$response = json_decode( file_get_contents( $url ) );

if( is_object( $response ) && property_exists( $response->cover , 'source' ) ) {
    $coverphoto_url = preg_replace( '/s720(\w*\.*)\d*(?<!\/)/i', $key_851 ,$response->cover->source );
    echo $coverphoto_url;
}
like image 35
Simon Avatar answered Sep 27 '22 22:09

Simon