It is possible to get the actual image url of a Facebook image using the Graph api??
For instance, for the below photo http://www.facebook.com/photo.php?fbid=3577553076
new GraphRequest(
facebookToken,
String.format("/%s/photos", idAlbum),
parameters,
HttpMethod.GET,
response -> {
try {
JSONArray photoArray = response.getJSONObject().getJSONArray("data");
photosAlbumAfterPagination = response.getJSONObject().getJSONObject("paging").getJSONObject("cursors").getString("after");
Gson gson = new Gson();
Type type = new TypeToken<List<FacebookPhotoResponse>>() {
}.getType();
List<FacebookPhotoResponse> list = gson.fromJson(photoArray.toString(), type);
} catch (JSONException e) {
e.printStackTrace();
}
}
).executeAsync();
Request the field attachments, where you will find the original image.
&fields=picture.type(large),attachments
There seems to be lack of documentation for this. It can simple be achieved in this way. In that url http://www.facebook.com/photo.php?fbid=357755307655174 , take out the id of the pic represented by fbid.In the above case it is 357755307655174. Now do a graph api query, to this object https://graph.facebook.com/357755307655174 . This will return a JSON with all the aspect ratio's present in their database and their actual URL's. Each data field following the format
{
"height": 1080,
"source": "https://scontent-a.xx.fbcdn.net/hphotos-xpf1/t31.0-8/10296099_566697856780203_6555830953677139074_o.jpg",
"width": 1980
}
Use the Graph Explorer to check once again the format of returned JSON data.The source is what you are looking for.
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
.
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"
}
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.