FAPI.Client.call

Method signature

Calling API methods with automated signature calculation.

FAPI.client.call(params, userCallback, resig)
ParameterRequiredDescription
paramsYesA set of key-value pairs for the called method (including the method name)
userCallbackYesThe function that will be called after the server response
resigNoIt is required when you want to prompt the user to confirm an action through a separate preview. In all other cases, the function call by specifying only 2 parameters.

Callback function

userCallback has a following signature:

function(status, data, error)

Where:

  • status - “ok” in case of success, “error” in case of error;
  • data - result object, e.g. [“565478477729”] for friends.get;
  • error - null in case of success, if an error is an object that contains the error code and description.

Example usage

function initCard() {
    var callback_users_getCurrentUser = function(method, result, data){
        if (result) {
            fillCard(result);
        } else {
            processError(data);
        }
    };
 
    var callback_friends_get = function(method, result, data){
        if(result) {
            var randomFriendId = result[getRandomInt(0, result.length)];
            var callback_users_getInfo = function(method, result, data) {
                if (result) {
                    document.getElementById("random_friend_name_surname").innerHTML = result[0]["first_name"] + " " + result[0]["last_name"];
                } else {
                    processError(data);
                }
            }
            FAPI.Client.call({"method":"users.getInfo", "fields":"first_name,last_name", "uids":randomFriendId}, callback_users_getInfo);
        } else {
            processError(data);
        }
    }
 
    FAPI.Client.call({"fields":"first_name,last_name,location,pic128x128","method":"users.getCurrentUser"}, callback_users_getCurrentUser);

    FAPI.Client.call({"method":"friends.get"}, callback_friends_get);
}