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

不问归期 提交于 2020-01-24 05:25:31

问题


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.


回答1:


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 :)




回答2:


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




回答3:


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;
}


来源:https://stackoverflow.com/questions/11917221/accessing-full-size-851x315-timeline-cover-photo-via-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!