This library is deprecated:
- If you are creating HTML5 app using Unity it's recommended to use ok-js-sdk
- If you are creating native app it's recommended to use webview oauth with viral widgets suggest/invite and post and REST requests
This SDK allows you to connect your Unity Android and iOS with Odnoklassniki.
Note: This version Odnoklassniki Unity SDK only supports Unity 5.X+. Check unity4x branch for older version support
An application registered within OK platform should have:
- Target platform checked (like ANDROID or IOS)
- EXTERNAL platform checked
- Client OAUTH checkbox checked
- A VALUABLE_ACCESS permission being checked or requested
- (recommended) LONG_ACCESS_TOKEN permission requested from api-support in order to be able to use tokens with long ttl
- A redirect url configured in application settings including okauth://ok12345 where 12345 is your application id on OK platform
- Fill in application parameters in
OdnoklassnikiSettings.asset
- Add the following entries to your
android.manifest
- within application tag
<activity android:name="ru.odnoklassniki.unity.OKAndroidPlugin"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<data android:scheme="okauth" android:host="INSERT_OK_APPLICATION_ID" />
</intent-filter>
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
<activity android:name="ru.odnoklassniki.unity.webview.OKWVActivity"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
where INSERT_OK_APPLICATION_ID should be in format: ok1234567890
- within manifest tag
<activity android:name="ru.odnoklassniki.unity.auth.AppAuthorization"/>
OK.Init(success =>
{
if (success) {
//Proceed to authorization
}
});
OK.Auth(success =>
{
if (success) {
//Authorization successful, you can now use Odnoklassniki API
}
});
There are 2 types of authorization based on whether native Odnoklassniki application (AppStore / Google Play) is installed: authorization via native application & authorization via webview.
Once authorized, you will receive an access token lasting for 30 minutes
OK.AccessToken
If you authorized via native Odnoklassniki application, you will also receive refresh token lasting for 30 days, which can be used to revalidate access token
OK.IsRefreshTokenValid
You need to take care of refreshing the access token
if (OK.isInitialized && OK.AccessTokenExpiresAt < DateTime.Now) {
if (OK.IsRefreshTokenValid) {
OK.RefreshAccessToken(success =>
{
//Token refreshed
});
} else {
OK.RefreshOAuth(success => {
//Token refreshed
}
}
}
OK.OpenInviteDialog(response => {
//Will be called after Invite API call
}, "Invite Message");
OK.OpenSuggestDialog(response => {
//Will be called after Suggest API call
}, "Suggest Message");
OK.OpenPhotoDialog(response => {
//Will be called after Upload API call
}, texture, "Description");
OK.OpenPublishDialog(response => {
//Will be called after Publish API call
}, new List<OKMedia>()
{
OKMedia.Photo(texture),
OKMedia.Text("Description")
});
response => {
if (response.Object != null && response.Object.ContainsKey("error_code")) {
string errorCode = response.Object["error_code"].ToString();
string errorMessage = response.Object["error_msg"].ToString();
//Debug.Log or show alert?
} else {
//Success
}
}
Is there a convenient way to see if Odnoklassniki widget is shown?
OKWidgets.HasActiveWidget() method does that.
How can I select specific canvas for widgets if I am using multiple canvases?
You can explicitly specify canvas to use with OKWidgets.canvas