1.0.6 • Published 2 years ago
@odnoklassniki/ok-apps-sdk v1.0.6
Odnoklassniki app sdk
Usage
import OKSDK from '@odnoklassniki/ok-apps-sdk';
// Init SDK
await OKSDK.init();For use in a browser, include the file dist/browser.min.js and use as follows
<script src="https://unpkg.com/@odnoklassniki/ok-apps-sdk/dist/browser.min.js"></script>
<script>
// Init SDK
OKSDK.init()
.then(mode => {...})
.catch(error => {...});
</script>API Reference
OKSDK.Methods
Contains groups of methods that avalable and recommended for use
Some of them return promise with response
Response fields
statusText with status ok | errordataData of response string | boolean | number | object
Example
const {status, data: appId} = await OKSDK.Methods.Utils.getAppId();Some of them return value synchronously
Example
const isSupported = OKSDK.Methods.Utils.isSupported(); // booleanSome of them need callback to be provided
Callback arguments
statusText with status ok | errordataData of response string | boolean | number | object
Example
const callback = (status, data) => {
console.log(data);
};
OKSDK.Methods.Utils.observeServiceCallbacks('DEVICE_ORIENTATION', callback);OKSDK.invoke
OKSDK.invokeUIMethod @Depricated
This methods allow you to call methods as it was done in previous versions of SDK
Parameters
methodrequired Method nameparamsoptional Array of parameterscallbackoptional Callback for getting result
Example
// Sending event to client
OKSDK.invoke('joinGroup', [groupId], ({status, data}) => {});OKSDK.Client.call
Call API methods
Parameters
paramsrequired Object with call params including method namecallbackoptional A function that will be called after the server respondsresigoptional Required when it is necessary to request user confirmation for any action through a separate preview. In all other cases, call the function with only 2 parameters.
Method can be used with callback or with promise
Example
// Sending event to client
const params = {
"method":"friends.get"
};
const callback = (status, data, error) => {
if (error) {
processError(error);
} else {
processFriendIds(data);
}
};
OKSDK.Client.call(params, callback);OR
// Sending event to client
const params = {
"method":"friends.get"
};
const data = await OKSDK.Client.call(params);