Developers Manual > SDK Integration > Facebook > Facebook API References in JavaScript > Facebook-appRequest

.appRequest(info, callback)

This method triggers Requests Dialog, which is invoked in-game via the Facebook SDK on iOS, Android and Canvas. Requests can contain a user-facing message as plain text, which is passed as a parameter when invoking the dialog, or they can contain specific information including in-game items and explicit calls to action. Requests give players a mechanism for inviting their friends to play a game. Requests are sent by a player to one or more specific friends, and always carry a call-to-action that the sender wants the recipient to complete. Recipients can choose to accept the request, or they can choose to ignore or decline it.

For more details, please refer to doc Requests.
NOTE: Request Dialog in Cocos SDK does not support Frictionless Requests for now.

Parameters

1
plugin.FacebookAgent.prototype.appRequest = function(info, callback){}
Name Type Required Description
info Object Yes The object to contain the details of the request.
callback Function No Callback function containing a result code and a JSON response.

info content:

It supports all the parameters listed in Dialog Parameters Section in the doc.

Callback function

If the sender sends any requests, code is plugin.FacebookAgent.CODE_SUCCEED and response is a JSON dictionary with two properties, request (a string containing the Request ID assigned by Facebook) and to (an array of string, each element being the Facebook ID of one of the selected recipients). If the sender doesn't send any requests, response will instead be null. The example of response is as below:

1
2
3
4
5
6
7
{
    "request": "420211088059698",
    "to": [
        "100002669403922",
        "100000048490273"
    ]
}

If there is some error, code is error code and response is a JSON containing error message as the example below,

1
2
3
{
    "error_message": "Action cancelled by user"
}

Example

1
2
3
4
5
6
7
8
9
10
11
12
var info = {
    "message": "Cocos2d-JS is a great game engine",
    "title": "Cocos2d-JS"
};
var facebook = plugin.FacebookAgent.getInstance();
facebook.appRequest(info, function (code, msg) {
    if(code == plugin.FacebookAgent.CODE_SUCCEED){
        //succeed
    } else {
        cc.log("Sending request failed, error #" + code + ": " + response);
    }
});

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.