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(status, data, error){
        if (data) {
            fillCard(data);
        } else {
            processError(error);
        }
    };
 
    var callback_friends_get = function(status, data, error){
        if(data) {
            var randomFriendId = result[getRandomInt(0, result.length)];
            var callback_users_getInfo = function(status, data, error) {
                if (data) {
                    document.getElementById("random_friend_name_surname").innerHTML = data[0]["first_name"] + " " + data[0]["last_name"];
                } else {
                    processError(error);
                }
            }
            FAPI.Client.call({"method":"users.getInfo", "fields":"first_name,last_name", "uids":randomFriendId}, callback_users_getInfo);
        } else {
            processError(error);
        }
    }
 
    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);
}