Facebook Graph API - How do you retrieve the different size photos from an album? - facebook

Ok, first off let me tell you I have no problems getting a user's photo album(s) and looping through the output to display all of the photos in the size I want.
However, if I want to call a photo like:
<img src="https://graph.facebook.com/<?=$this->session->page->photo_id?>/picture?access_token=<?=$this->session->member->facebook_access_token?>" />
I cannot figure out how to tell it the size I want it to show.
In this sample code from Facebook you will see that whey retrieving the album each photo in the array comes back with the different sizes in this sample array. I could just save the thumbnail url from this, but I don't want to store it, just retrieve when needed.
{
"id": "10150146071831729",
"from": {
"name": "Facebook",
"category": "Product/service",
"id": "20531316728"
},
"picture": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_s.jpg",
"source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_n.jpg",
"height": 483,
"width": 720,
"images": [
{
"height": 483,
"width": 720,
"source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_n.jpg"
},
{
"height": 120,
"width": 180,
"source": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_a.jpg"
},
{
"height": 87,
"width": 130,
"source": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_s.jpg"
},
{
"height": 50,
"width": 75,
"source": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash1/168119_10150146071831729_20531316728_7844072_5116892_t.jpg"
}
],
....... continued...
}
There has to be a way to retrieve these different sizes.
Thanks.

Facebook provides a type option for the picture field, for example, you can specify something like:
<img src="https://graph.facebook.com/xxx/picture?access_token=yyy&type=normal />
where the type parameter can be one of square, small, normal, or large for profile pictures or thumbnail, normal, album for album pictures.
Source: http://developers.facebook.com/docs/reference/api/user/ (under Connections section)
Edit: Added different options for album pictures

Thought I'd share a little trick in getting larger image sizes from the Graph API. Facebook as a little convention with image URLs that's not very obvious. For instance, take the following URL:
https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-prn2/t1/1185356_10201176263222205_1153673992_s.jpg
Notice the _s.jpg at the end? That determines the size of the image. You can change this to _o.jpg to get the "original" full size version. In other words, update the image URL to:
https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-prn2/t1/1185356_10201176263222205_1153673992_o.jpg
Every Facebook image has an _o.jpg version. Worst case, you get something the same size as the thumbnail. If that's the case, you're no better off than you were before.

here src_big and src are different size image url source
function get_photos_by_album_id($album_id){
if($album_id)
$fql = 'SELECT pid,src_big,owner,link,position,created,caption,src FROM photo WHERE aid="'.$album_id.'" ORDER BY created DESC LIMIT 0,6';
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $this->facebook->api($param);
return $fqlResult;
}

Related

How to make soundcloud oembed endpoint return an iframe with a height of 300?

I am using souncloud's oembed endpoint, and the default height is 400, which is too big.
I need to adjust it, i have tried this:
https://soundcloud.com/oembed?format=json&height=300&url=https://soundcloud.com/giorgiomartini
But that only changes the height of the artwork, notice height at the end of the html key (the iframe), on the json i get back:
{
"version": 1,
"type": "rich",
"provider_name": "SoundCloud",
"provider_url": "http://soundcloud.com",
"height": 450,
"width": "100%",
"title": "Giorgio Martini",
"description": null,
"thumbnail_url": "http://i1.sndcdn.com/avatars-000336450748-qnkjy0-t500x500.jpg",
"html": "<iframe width=\"100%\" height=\"450\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?visual=true&url=https%3A%2F%2Fapi.soundcloud.com%2Fusers%2F1367858&show_artwork=true&height=300\"></iframe>",
"author_name": "Giorgio Martini",
"author_url": "https://soundcloud.com/giorgiomartini"
}
I do need however to change the height of the iframe itself... is there a waywith oembeed to do this?
Or do i have to do some kind of string manipulation on the response i get back to change the height from 400 to say 300?
Thanks
According to the documentation, there is an URL parameter called maxheight - simply set this to 300:
https://soundcloud.com/oembed?format=json&maxheight=300&url=https://soundcloud.com/giorgiomartini
I would recommend using CSS instead to make the video iframe responsive, so it always fills up its parent container no matter the size of the window, on any device. See Fluid Width Video and the VideoWrapper class.

I could not find json file in OSMBuilding

I make clickable buildings with OSM Buildings. When I click a building, I get Building ID. However, I could not get height of a building because I cannot fing JSON file to get this value.
Codes are here:
var map = new L.Map('map');
map.setView([52.52111, 13.40988], 16, false);
new L.TileLayer('https://{s}.tiles.mapbox.com ...
https://codepen.io/osmbuildings/pen/JdaaRM
To sum up, I want to get height of a building with using OSM Building.
The height is contained in the JSON file.
See this example here: https://b.data.osmbuildings.org/0.2/anonymous/tile/16/35210/21491.json. It contains a properties field which in turn contains height and levels:
"id": "w24273225",
"type": "Feature",
"properties": {
"height": 65,
"levels": 17
},
"geometry": {
"type": "Polygon",
"coordinates": [
[...]
]
}
The height and level information is only present if the building in OSM actually has this information. This isn't the case for every building.

How to get a larger scraped feed picture?

I read the documentation, and the scraped feed picture is stored inside the picture tag.
Unfortunately, it returns a small version of the picture. I need a larger one.
How can I do it this Graph API? Seems that API/workarounds have been changed.
No way anymore? Can't find anything in the Facebook documentation.
This should work:
/post-id?fields=picture.type(large)
/post-id?fields=picture.width(100).height(100)
Source: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2?locale=en_US#fieldexpansion
Edit: Actually, it does not seem to work for the user feed, but there is an "object_id" in the result of /me/feed. You can do another request to that object_id:
/object-id
...resulting in all the available images sizes:
"images": [
{
"height": 526,
"source": "https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpf1/v/t1.0-9/10444402_888067974538310_2165197996181662459_n.jpg?oh=4518cc6608a14a2108aeaf61bcb60d09&oe=5501E78D&__gda__=1426703335_d71feeeb9aa6d8fd58085cd6074101e3",
"width": 526
},
{
"height": 480,
"source": "https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpf1/v/t1.0-9/p480x480/10444402_888067974538310_2165197996181662459_n.jpg?oh=bc0736fc9f74b1a4d89727ae5526dd3b&oe=5517CD73&__gda__=1427230414_1197a9870346dbaaf300c2ea0e359402",
"width": 480
},
...
New way - /{post_id}?fields=full_picture

Facebook Like - displaying the correct image and content

I have a website (not a FB app) that has a page of which I have added a "Like" button to, using the facebook like button generator.
I am having trouble specifying the exact image I want to share along with a specific content.
I have tried the Open Graph meta tags, but these seem to be ignored (possibly they are only for FB apps??)
I'm using the following code for the button:
<div class="fb-like" data-href="https://www.MYURL" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
The functionality itself is working. It will share the link onto FB but not using the content/image I would prefer.
What am I doing wrong?
Debug
{
"og_object": {
"type": "website",
"updated_time": "2014-09-05T09:58:07+0000",
"url": "https://www.MYURL",
"id": "MYNUMBER"
},
"share": {
"comment_count": 0,
"share_count": 0
},
"id": "https://www.MYURL"
}

How can I get exact Facebook like count?

I have Facebook like button on my website, created as following:
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2fexample.com&layout=button_count&show_faces=false&width=110&action=like&colorscheme=light&height=35"
scrolling="no" frameborder="0"
allowTransparency="true">
</iframe>
Like count at the moment is displayed as 1,5 k. I would like to get exact number of likes.
I have tried to query http://graph.facebook.com/?id=http%3A%2F%2Fexample.com, but response I am getting is:
{
"id": "http://example.com",
"shares": 349
}
I have also tried to use FQL:
http://graph.facebook.com/fql?q=SELECT
like_count,total_count,click_count,commentsbox_count
FROM link_stat
WHERE url='http%3A%2F%2Fexample.com'
And response is:
{
"data": [
{
"like_count": 251,
"total_count": 349,
"click_count": 0,
"commentsbox_count": 0
}
]
}
How can I get exact count number?
The exact like count is the total_count you see there.
For some reason Facebook counts comments and shares as a like with its like button.
Don't forget that http://example.com is different than https://example.com and http://www.example.com/
Make sure you add up all those aliasses.