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,
http://a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/xxxxxx_xxxxxxxxxxxxxxx_xxxxxxxxxx_n.jpg
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.
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 :)
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
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With