OKSDK.Widgets.invite

Method is used to invite a friend to a game via invite/suggest widget.

Invite can be sent only if:

  • receiver is a friend of current user;
  • receiver enabled game invites in profile settings;
  • receiver has not yet installed a game to which is being invited.

Method signature

OKSDK.Widgets.invite(returnUrl, options)

Where:

  • returnUrl - URL on which user will be redirected after an invite was confirmed / declined. Optional parameter;
  • options - additional parameters, object:
    • autosel - amount of auto selected friends;
    • comment - default invite text;
    • custom_args - additional parameters that are going to be passed to a game if it was launched from an invite notification;
    • nohead - show OK header in a widget window;
    • state - additional parameters that are going to be passed in method’s result;
    • target - list of user ids that are going to be auto selected;
    • target_only - show only users specified in a target parameter;

Full parameters description is available here

Return URL message

If returnUrl parameter was specified and options.silent was not user will be redirected to a specified URL.

Method’s result will be passed in an URL as additional GET parameters:

  • code - result code:
    • OK - invite was successfully sent;
    • CANCELLED - request was cancelled by user;
    • PARAM_SIGNATURE and other - an error occurred while sending an invite. Full error list is available here
  • selected - list of user IDs to whom invites were sent;
  • result - method’s result as an object. Contains all other result parameters;
  • error_code - error code;
  • error_msg - error text;
  • sig - request signature.

Response example for a successfully sent invite case

https://return.url/
   ?code=OK
   &result={"code":"OK","selected":"[1234567890]"}
   &selected=[1234567890]
   &sig=297a083bc6a3e15*****c08f8ff52cc3

Response example for a cancelled request

https://return.url/
   ?code=CANCELLED
   &error_code=12
   &error_msg=Operation was cancelled by user
   &message=Operation was cancelled by user
   &result={"error_code":"12","code":"CANCELLED","error_msg":"Operation was cancelled by user","message":"Operation was cancelled by user"}
   &sig=769bab70551*****5551182e5b1e7e22

Response example in case of an error

https://return.url/
   ?code=PARAM_SIGNATURE
   &error_code=104
   &error_msg=Bad signature
   &message=Bad signature
   &result={"error_code":"104","code":"PARAM_SIGNATURE","error_msg":"Bad signature ","message":"Bad signature "}

Window postMessage

If returnUrl was not specified then postMessage with method’s result will be sent to a parent window.

Message will contain data field with all the valuable data about method’s result. This data is same as in case of returnUrl specified.

Response example for a successfully sent invite case

{
    "code": "OK",
    "selected": "[1234567890]"
}

Response example for a cancelled request

{
    "error_code": "12",
    "code": "CANCELLED",
    "error_msg": "Operation was cancelled by user",
    "message": "Operation was cancelled by user"
}

Response example in case of an error

{
    "error_code": "104",
    "code": "PARAM_SIGNATURE",
    "error_msg": "Bad signature ",
    "message": "Bad signature "
}

You can add an eventListener which will process such messages:

    window.addEventListener('message', function (widgetMessage) {
        console.log(JSON.stringify(widgetMessage.data));
        // result handling code goes here
    }, false);
    

Example usage

OKSDK.Widgets.invite(
    null,
    {
        "autosel": 3,
        "nohead": false,
        "popup": true
    }
)

Method call result in a widget being opened in a new window with a dialog where user can select friend to invite into a game:

Game invite widget