General information
JavaScript SDK is SDK of built-in applications that are iframes, the content of which is located on the developer’s server.
JS SDK is supported for:
- all web apps launched on out desktop platform ok.ru;
- all new mobile apps launched on our mobile platform in an iframe (partially)
If your application is still launched as an external page you can request us to launch it in an iframe sending a request to api-support@ok.ru
Methods supported on mobile are marked with icon
Methods available ONLY on mobile are marked with icon
Setting up SDK
Connecting a library:
When using js + flash in a flash application, the “wmode=opaque” parameter must be set.
After every transition inside an iframe it is necessary to perform an initialization again with the FAPI.init method, as well as pass the following parameters:
- api_server
- apiconnection
- web_server
- application_key
- session_key
- session_secret_key
Using SDK
SDK allows you to:
- invoke OK REST API methods;
- implement social mechanics - posts, invites and notifications between users;
- implement in-app purchases and subscriptions;
- implement in-app ads;
- work with browser window and iframe in which app is launched.
SDK initialization
- FAPI.init - SDK initialization. Must be called before calling any method (both when launching applications for the first time and when doing internal transitions across the frame).
In-app purchases
- FAPI.UI.showPayment - dialog for buying game currency or game items;
- FAPI.invokeUIMethod(“showPaymentSubscription”) - dialog for purchasing an in-game subscription.
In-app ads
- FAPI.UI.loadAd - prepares a rewarded ad to show during game session;
- FAPI.UI.showLoadedAd - shows a rewarded ad previously prepared during game session;
- FAPI.UI.showAd- shows an interstitial ad during game session;
- FAPI.UI.requestBannerAds - request a banner ad;
- FAPI.UI.showBannerAds - show banner with an ad;
- FAPI.UI.hideBannerAds - hide banner with an ad;
- FAPI.UI.isBannerAdsVisible - check if banner is displayed;
- FAPI.UI.getBannerFormats - get supported banner ads display formats;
- FAPI.UI.setBannerFormat - set banner ads display format;
- FAPI.UI.setBannersCount - set amount of banners to be shown simultaneously (desktop only);
- FAPI.UI.isAdBlockEnabled - check if adblock is enabled (desktop only).
Social mechanics
Other game mechanics
Working with other OK services
Anonymous games
- FAPI.invokeUIMethod(“showLogin”) - forced authorization without user’s approval;
- FAPI.UI.showLoginSuggestion - suggest user to authorize.
Working with REST API
- FAPI.UI.showPermissions - dialog for requesting permissions (e.g. to change the user status);
- FAPI.Client.call - calling API methods with automated signature calculation.
Utility methods
- FAPI.Util.getRequestParameters - getting parameters when addressing the application;
- FAPI.UI.getPageInfo - information about the page (height, width, scrolling position, position of the application iframe);
- FAPI.UI.changeHistory - changes current URL on Odnoklassniki for user;
- FAPI.UI.scrollTo - scrolls the page to a specific position;
- FAPI.UI.scrollToTop - scrolls the page to the top;
- FAPI.UI.setWindowSize - changing the size of application container;
- FAPI.invokeUIMethod(“requestDesktopIcon”) - request to create a shortcut for a game;
- FAPI.invokeUIMethod(“requestFullscreen”) - opens game iframe in a fullscreen mode;
- FAPI.invokeUIMethod(“showHideLocation”) - shows a hint to hide browser’s navigation bar;
- FAPI.invokeUIMethod(“observeServiceCallbacks”) - subscription to service events;
- FAPI.UI.openComplaintForm - allows games to directly raise the contact Customer Support Team layer in a game.
Other features
- FAPI.UI.showPaymentPromo - dialog informing about a current payment system promotion;
- FAPI.UI.showPortalPayment - dialog for buying OKs (Odnoklassniki’s internal currency).
- FAPI.invokeUIMethod(“updateStickerSets”) - updates sticker sets on mobile OK app;
API_callback
Methods from the FAPI.UI group don’t require the callback function to be passed. After the method is executed, a global function will be called, and the developer must realize it. The function must have the signature:
Here:
- method - the name of the method called
- result - the result of the execution (“ok” if successful, “cancel” if the user canceled the action)
- data - additional information, for example, for showInvite() – a list of IDs of invited friends, separated by commas, in the string format.