hopelesscoder
09-18-2011, 08:37 AM
I have been searching for a way to display facebook api friends.getAppUsers in set of 5.
I am able to do this if i hard code it but I cant seem to find and comprehend a method to do this dynamically.
What i want to achieve is, if i have 43 friends using the application, the code should allow users to view this result in set of 5.
-prevBtn- friend1 friend2 friend3 friend4 friend5 -nextBtn-
upon clicking on the nextBtn,
-prevBtn- friend6 friend7 friend8 friend9 friend10 -nextBtn-
etc
i am actually relatively new to Javascript and Facebook Codings.. so any help would really be great! Thanks!
here are my codes:
<div id="fb-root"></div>
<table width="750px" height="185px" background="Image/friends.jpg">
<tr>
<td align="right">
<a href="#"onClick="prev();return false"><img src="Image/prevFriend.jpg" width="36" height="154"></a>
</td>
<td width="89%">
<div id="profile_pics" align="left"></div>
</td>
<td>
<a href="#" onClick="next();return false">Image/nextFriend.jpg" width="36" height="154"></a>
</td>
</tr>
</table>
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
var profilePicsDiv = document.getElementById('profile_pics');
var NameDiv = document.getElementById('name');
var containDiv = document.getElementById('container');
FB.init({ appId: 'xxxxxxxxxxxx', status: true, cookie: true, xfbml: true });
FB.Event.subscribe('auth.sessionChange', function (response) {
if (response.session) {
window.location.reload();
} else {
window.location.reload();
}
});
FB.getLoginStatus(function(response) {
if (!response.session) {
profilePicsDiv.innerHTML = '<em></em>';
containDiv.innerHTML = '<em>You are not connected </em> ';
return;
}
FB.api({ method: 'friends.getAppUsers' },
function(result)
{
var markup = '';
var numFriends = result ? Math.min(5,result.length) : 1;
if (numFriends > 0)
{
for (var i=0; i<numFriends; i++)
{
markup +=
(
'<fb:profile-pic size="square" ' +
'uid="' + result[i] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic>'
);
}
}
profilePicsDiv.innerHTML = markup;
FB.XFBML.parse(profilePicsDiv);
});
});
function next(){
FB.api({ method: 'friends.getAppUsers' },
function(result)
{
var markup = '';
var numFriends = result ? Math.min(10,result.length):1;
if (numFriends > 5)
{
for (var j=5; j<numFriends; j++)
{
markup +=
(
'<fb:profile-pic size="square" ' +
'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic>'
);
}
}
else{
if (numFriends > 0)
{
for (var j=0; j<numFriends; j++)
{
markup +=
(
'<fb:profile-pic size="square" ' +
'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic> '
);
}
}
};
profilePicsDiv.innerHTML = markup;
FB.XFBML.parse(profilePicsDiv);
});
}
function prev(){
FB.api({ method: 'friends.getAppUsers' },
function(result)
{
var markup = '';
var numFriends = result ? Math.min(5,result.length):1;
if (numFriends > 0)
{
for (var j=0; j<numFriends; j++)
{
markup +=
(
<fb:profile-pic size="square" ' +
'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic>'
);
}
}
profilePicsDiv.innerHTML = markup;
FB.XFBML.parse(profilePicsDiv);
});
}
I am able to do this if i hard code it but I cant seem to find and comprehend a method to do this dynamically.
What i want to achieve is, if i have 43 friends using the application, the code should allow users to view this result in set of 5.
-prevBtn- friend1 friend2 friend3 friend4 friend5 -nextBtn-
upon clicking on the nextBtn,
-prevBtn- friend6 friend7 friend8 friend9 friend10 -nextBtn-
etc
i am actually relatively new to Javascript and Facebook Codings.. so any help would really be great! Thanks!
here are my codes:
<div id="fb-root"></div>
<table width="750px" height="185px" background="Image/friends.jpg">
<tr>
<td align="right">
<a href="#"onClick="prev();return false"><img src="Image/prevFriend.jpg" width="36" height="154"></a>
</td>
<td width="89%">
<div id="profile_pics" align="left"></div>
</td>
<td>
<a href="#" onClick="next();return false">Image/nextFriend.jpg" width="36" height="154"></a>
</td>
</tr>
</table>
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
var profilePicsDiv = document.getElementById('profile_pics');
var NameDiv = document.getElementById('name');
var containDiv = document.getElementById('container');
FB.init({ appId: 'xxxxxxxxxxxx', status: true, cookie: true, xfbml: true });
FB.Event.subscribe('auth.sessionChange', function (response) {
if (response.session) {
window.location.reload();
} else {
window.location.reload();
}
});
FB.getLoginStatus(function(response) {
if (!response.session) {
profilePicsDiv.innerHTML = '<em></em>';
containDiv.innerHTML = '<em>You are not connected </em> ';
return;
}
FB.api({ method: 'friends.getAppUsers' },
function(result)
{
var markup = '';
var numFriends = result ? Math.min(5,result.length) : 1;
if (numFriends > 0)
{
for (var i=0; i<numFriends; i++)
{
markup +=
(
'<fb:profile-pic size="square" ' +
'uid="' + result[i] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic>'
);
}
}
profilePicsDiv.innerHTML = markup;
FB.XFBML.parse(profilePicsDiv);
});
});
function next(){
FB.api({ method: 'friends.getAppUsers' },
function(result)
{
var markup = '';
var numFriends = result ? Math.min(10,result.length):1;
if (numFriends > 5)
{
for (var j=5; j<numFriends; j++)
{
markup +=
(
'<fb:profile-pic size="square" ' +
'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic>'
);
}
}
else{
if (numFriends > 0)
{
for (var j=0; j<numFriends; j++)
{
markup +=
(
'<fb:profile-pic size="square" ' +
'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic> '
);
}
}
};
profilePicsDiv.innerHTML = markup;
FB.XFBML.parse(profilePicsDiv);
});
}
function prev(){
FB.api({ method: 'friends.getAppUsers' },
function(result)
{
var markup = '';
var numFriends = result ? Math.min(5,result.length):1;
if (numFriends > 0)
{
for (var j=0; j<numFriends; j++)
{
markup +=
(
<fb:profile-pic size="square" ' +
'uid="' + result[j] + '" ' + 'facebook-logo="false"' + 'linked="false"' +
'></fb:profile-pic>'
);
}
}
profilePicsDiv.innerHTML = markup;
FB.XFBML.parse(profilePicsDiv);
});
}