Facebook how to get actual photo URL using Graph API?

  • From https://developers.facebook.com/docs/graph-api/using-graph-api :

By default, not all fields in a node or edge are returned when you make a query. You can choose the fields or edges that you want returned with the fields query parameter.

That's why when you retrieve a photo, you may only get created_time, name and id.

  • From https://developers.facebook.com/docs/graph-api/reference/photo/ :

source field is deprecated in latest API (v2.8). Use images instead.

So your query may look like this:

GET graph.facebook.com/{photo-id}?fields=images

Response should be like this:

{

"images":[
    {
        "height":358,
        "source":"https://scontent.xx.fbcdn.net/v/t1.0-9/15327427_585435148333529_xxxxxxxxxxxx_n.jpg?oh=xxxxxxxx&oe=xxxxxxxxx",
        "width":518
    },
    {
        "height":320,
        "source":"https://fb-s-c-a.akamaihd.net/h-ak-xtl1/v/t1.0-0/p320x320/15327427_xxxxxxxxxxxxxx_n.jpg?oh=xxxxxxxxxx&oe=xxxx&__gda__=xxxxxxxxxxxx",
        "width":463
    },
    {
        "height":130,
        "source":"https://fb-s-c-a.akamaihd.net/h-ak-xtl1/v/t1.0-0/p130x130/15327427_xxxxxxxxxxxxxx_n.jpg?oh=xxxxxxxxxxx&oe=xxx&__gda__=xxxxxxxxxxxxxxxxxx",
        "width":188
    },
    {
        "height":225,
        "source":"https://fb-s-c-a.akamaihd.net/h-ak-xtl1/v/t1.0-0/p75x225/15327427_xxxxxxxxxxxxxxx_n.jpg?oh=xxxxxxxxxxxxxxxxx&oe=xxxxxxxxxxxxxxxxxx&__gda__=xxxxxxxxxxxxxxxxxx",
        "width":325
    }
],
"id":"585435148333529"

}

Request the field attachments, where you will find the original image.

&fields=picture.type(large),attachments

Is there some graph api way to achieving this?

Therefore, you’d have to look at the source field of the photo object:

source:

The source image of the photo - currently this can have a maximum width or height of 720px, increasing to 960px on 1st March 2012

string representing a valid URL

That’ll give you the original size the photo was uploaded for smaller images, or resized to max. 960px in each direction.

For even larger sizes, you’d have to check the images field:

images:

The 4 different stored representations of the photo

array of objects, containing height, width, and source fields

This “promises” to deliver much larger sizes (f.e. 2048×1417px) – but be aware, these entries will still deliver a smaller image if the original one wasn’t as large as requested.