I am using the Facebook API to browse albums, choose an album and then output the photos on to my page.
I login successfully with Facebook. Accept app permissions. It outputs all albums on to a page to select from. I select an album and pass the album ID to another page where I output the photos. But the response doesn't have all photo fields, only id
and created_time
.
For example:
//load fb api
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
//Initialise
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXX',
status : true,
xfbml : true,
cookie : true,
version : 'v2.4'
});
}
//Get albums - This works fine.
FB.api( "/me/albums", function (response) {
if (response && !response.error) {
data = response.data;
//Output albums...
}
});
I select an album and pass it to a page where I output the photos like this:
FB.api(
"/ALBUM_ID/photos",
function (response) {
if (response && !response.error) {
console.log(response);
}
}
);
This is where it breaks. The output in the log looks like:
Object {data: Array[1], paging: Object}
data: Array[1]
0: Object
created_time: "2014-05-07T10:39:31+0000"
id: "xxxxxxxxxxxxxxx"
And that's it. No other fields. There are no errors in the log. I don't understand why I am only getting some data.
The Graph API v2.4 reduces the number of fields in default responses.
https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/
Fewer default fields for faster performance: To help improve performance on mobile network connections, we've reduced the number of fields that the API returns by default. You should now use the
?fields=field1,field2
syntax to declare all the fields you want the API to return.
In short, explicitly state which fields you require as part of your request.