Making a Request to Capture User Friendships
Much like our previous Person
request, we can make a simple get request to capture owner friends:
//get owner friends
osapi.people.get({userId: '@owner', groupId: '@friends', count: 10})
.execute(function(result){
if (!result.error){
var friends = result.list;
var html = '';
for (var i = 0; i < friends.length; i++){
html += friends[i].name.formatted + '';
}
}
});Again, this request can be split up into three individual sections:
osapi.people.get(...)is a standardgetmethod that can be used to capture any user data. In this case, we indicate within the JSON passed into this function that we would like to capture information from theownerof the application where thegroupIdisfriends. These are simple strings stating that we would like to capture the owner’s friends.execute(...)will initialize the owner friend data request.The callback, listed as the parameter in the
executefunction, will be hit when the owner friend data request completes, and contains all friendPersonobjects for the owner (friendsparameter). From this result, we can get the number of friends returned using.totalResultsor loop through the list ofPersonobjects for each friend.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access