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 standard get method 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 the owner of the application where the groupId is friends. 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 execute function, will be hit when the owner friend data request completes, and contains all friend Person objects for the owner (friends parameter). From this result, we can get the number of friends returned using .totalResults or loop through the list of Person objects for each friend.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.18.101