FAPI.Client.call

Calling API methods with automated signature calculation.

Parameters

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.

userCallback function has the form:

function(status, data, error) {
  /*
  * 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
  */
}

Examples

Call without resig

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);
}

Call with resig

function API_callback(method, result, data) {
    alert("Method "+method+" finished with result "+result+", "+data);
     if (method == "showConfirmation" && result == "ok") {
         FAPI.Client.call(feedPostingObject, function(status, data, error) {
            console.log(status + "   " + data + " " + error["error_msg"]);
        }, data);
    }
}
 
function publish() {
    var description_utf8 = "Can I publish?";
    var caption_utf8 = "Published text";
    feedPostingObject = {method: 'stream.publish',
                        message: description_utf8,
                     attachment: JSON.stringify({'caption': caption_utf8}),
                   action_links: '[]'
                        };
    sig = FAPI.Client.calcSignature(feedPostingObject);
    FAPI.UI.showConfirmation('stream.publish', description_utf8, sig);
}