Android SDK

Github repository: ok-android-sdk

Android application with OK SDK example: ok-android-sdk/odnoklassniki-android-sdk-example

Android SDK allows to authorize users via client authorization, publish new posts, invite friends to a game, send notifications and invoke REST methods.

Before using SDK you need to be sure everything is configured correctly for your app:

  • Android platform is added to your app’s platforms list;
  • client authorization is enabled;
  • redirect_uri okauth://ok{APP_ID} is added to redirect_uri’s list;
  • application has all required API permissions. It is recommended to have LONG_ACCESS_TOKEN permission enabled for native apps.

To import it with gradle do the following:

  • add this code to dependencies part of build.gradle file
compile 'ru.ok:odnoklassniki-android-sdk:2.0.3'
  • correct your AndroidManifest.xml file:
    • enable INTERNET permission
  <uses-permission android:name="android.permission.INTERNET"/>
    
* add OAuth Activity and set your app's APP_ID to the value
  <activity
        android:name="ru.ok.android.sdk.OkAuthActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="ok{APP_ID}"
                android:scheme="okauth"/>
        </intent-filter>
    </activity>
    
* in case of using widgets add specific Activities for each widget to be used
  <activity android:name="ru.ok.android.sdk.OkPostingActivity"/>
    <activity android:name="ru.ok.android.sdk.OkAppInviteActivity"/>
    <activity android:name="ru.ok.android.sdk.OkAppSuggestActivity"/>
    

SDK usage example

Creating Odnoklassniki object instance:

Odnoklassniki.createInstance(this, APP_ID, APP_KEY);
Odnoklassniki.getInstance();

Authorization (requestAuthorization):

odnoklassniki.requestAuthorization(OkListener, REDIRECT_URI, OkAuthType.ANY, OkScope.VALUABLE_ACCESS, OkScope.LONG_ACCESS_TOKEN);

REST method invocation (request):

odnoklassniki.request(METHOD_NAME, params, "GET");

Publish widget - performPosting, invite / suggest widget - performAppInvite / performAppSuggest):

odnoklassniki.performPosting("{\"media\":[{\"type\":\"text\",\"text\":\"hello world!\"}]}", false, params, OkListener);
odnoklassniki.performAppInvite(OkListener, params);
odnoklassniki.performAppSuggest(OkListener, params);