Developers » Mobile SDK
Mobile SDK
1. Connecting to the app
2. Mobile Client API methods
    2.1. showInviteBox
    2.2. showRequestBox
    2.3. showShareBox
    2.4. showSettingsBox
    2.5. showOrderBox
    2.6. showLeaderboardBox
3. Processing events
    3.1. VK.addCallback
    3.2. VK.removeCallback
4. Calling API methods

Mobile SDK allows working with a native interface on mobile VK apps and is designed for HTML5 games on our platform.
1. Connecting to the app
To use Mobile SDK, add a connection script to the <head> page:

<script src="https://vk.com/js/api/mobile_sdk.js"  type="text/javascript"></script>


Then initialize the VK object:

<script type="text/javascript">
  VK.init(function() {
      // API initialization succeeded
      // Your code here
  }, function() {
     // API initialization failed
     // Can reload page here
}, '5.60');
</script>
2. Mobile Client API methods
These methods are used for working with the native interface of mobile apps. Review the Mobile Client API methods list for Javascript and Flash SDK.

2.1. showInviteBox
Parameters: �

This opens a window to invite user friends to the app. After closing the window, the event onInviteBoxDone is called with these values passed:
  • status (string) � action status: cancel � canceled by user, success � operation successful, fail � operation failed;
  • [data (array) � an array of user IDs belong to those who did not receive invites (status = fail).]

2.2. showRequestBox
Parameters: user_id (integer), message (string), request_key (string)

This opens a window to send user ��user_id��, a request with the text ��message��. ��request_key�� is a random string to track conversion (request_key is passed in the app�s launch parameters if the launch was requested). After closing the window, the event ��onRequestBoxDone�� is called with these values passed:

  • status (string) � action status: cancel � canceled by user, success � operation successful, fail � operation failed;
  • [data (integer) � error code for status = fail].

Before calling ��showRequestBox��, it is necessary to acquire a list of users to whom you can send requests using the API method friends.getAppUsers.

2.3. showShareBox
Parameters: message (string), attachments (array), target (string)

This opens a window for sharing the text ��message�� and attachments ��attachments��. target = wall � sharing to the wall, target = im � sharing via private messages. A post may have no more than 2 attachments � a photo and a link (if target = im, the link needs to be indicated in the message text message). After closing the window, the event �onShareBoxDone� is called with these values passed:
  • status (string) � action status: cancel � canceled by user, success � operation successful, fail � operation failed;
  • [data (integer) � error code for status = fail].

2.4. showSettingsBox
Parameters: settings (integer)

This opens a windows for requesting access rights to the app. The parameters ��settings�� is a bit mask for requested access rights. If ��settings�� = ��0��, then the user will be permitted all possible access rights. After closing the window, the event ��onSettingsBoxDone�� is called with these values passed:
  • status (string) � action status: cancel � canceled by user, success � operation successful, fail � operation failed;;
  • [data (string) � new access_token].

2.5. showOrderBox
Parameters: item (string)

This opens a window for purchasing products in an app. The parameter ��item�� contains the name of the product that will be sent in payment notifications. After closing the window, the event onOrderBoxDone is called with these values passed:
  • status (string) � action status: cancel � canceled by user, success � operation successful, fail � operation failed;
  • [data (integer) � error code for status = fail].

Add payment testers in app settings in the section �Payments�. The accounts of testers should have at least one vote. While spending votes, they are not charged to the testers� accounts.

2.6. VK.callMethod(�showLeaderboardBox�, user_result)
This shows a window displaying the app�s tournament standings. The tournament standings may show user progress according to points or level earned (the type of tournament standings is selected in the �Manage app� section). user_result shows the current user�s result.
3. Processing events
3.1. VK.addCallback
Parameters: string eventName, function callback.

Adds the function callback as an event processor eventName.

3.2. VK.removeCallback
Parameters: string eventName, function callback.

Deletes the function callback from the event processor eventName.
4. Calling API methods
VK API methods allow working with VK user and community data. To communicate with API methods in Mobile SDK, use the function VK.api. It takes the following parameters:
  • methodName (string) � API method name;
  • params (object) � Object containing method parameters;
  • callback (function) � Function to which the acquired result will be passed after the method is executed.

API method parameters are passed in the sequence �key�: �value�.


By continuing to browse, you consent to our use of cookies. You can read our Cookie Policy here.