Reputation: 5669
Im getting the album names from facebook and writing them out on the page with the below code. The problem is that it is including the undefined ones also, so it writes two "Wall Photos", so how can I prevent it from writing out the undefined ones?
FB.api('/xxxxxxxxxxxxxxx/albums', function(response) {
if (response && response.data && response.data.length){
var ul = document.getElementById('fb-albumslist');
for (var i=0, l=response.data.length; i<l; i++) {
if (response.data !== "undefined"){
var
album = response.data[i],
li = document.createElement('li'),
a = document.createElement('a');
a.innerHTML = album.name;
a.href = album.link;
li.appendChild(a);
ul.appendChild(li);
}
}
}
});
And on the page it is writing out:
Wall Photos
Wall Photos (this is undefined)
Cover Photos
Profile Picture
Im trying with the "if (response.data !== "undefined"){" but Im not sure how to do it? Any input appreciated, thanks!
Upvotes: 0
Views: 1127
Reputation: 38115
It seems that Facebook is creating another Wall Photos album with these properties:
{
"id": "YYYY",
"from": {
"name": "AAAA",
"id": "XXX"
},
"name": "Wall Photos",
"privacy": "custom",
"type": "friends_walls",
"created_time": "2011-02-02T08:54:20+0000",
"updated_time": "2011-02-02T08:54:20+0000",
"can_upload": false
},
I'm not sure the purpose of this album but the best thing to do is to check if the link
field exists otherwise skip:
if(!album.link) continue;
Upvotes: 1