Integrating VKontakte API in a Mobile Application
VKontakte API is one of the few major social graphs available for CIS market integration. Main scenarios: VK ID login, profile import, wall post publishing, friend list access. API uses OAuth 2.0, but token handling differs from standard OAuth flow.
VK ID Authorization
Official SDK: VKID (iOS and Android, open source on GitHub). Replaced obsolete VK-ios-sdk and VK-android-sdk.
iOS:
import VKID
let vkid = try! VKID(config: Configuration(appCredentials: AppCredentials(
clientId: "YOUR_APP_ID",
clientSecret: "YOUR_SECRET"
)))
vkid.authorize(with: AuthConfiguration(flow: .authorizationCode)) { result in
switch result {
case .success(let session):
let accessToken = session.accessToken.value
// Token for API requests
case .failure(let error):
print(error)
}
}
Android:
val vkid = VKID(context)
vkid.authorize(
activity = this,
config = AuthConfiguration.build {
oAuth = OAuthListWidget.OAuthItem.VK
}
) { result ->
when (result) {
is AuthResult.Success -> val token = result.token.accessToken
is AuthResult.Failure -> // error handling
}
}
VK token is user-specific, bound to user_id and permission set (scope). Scope requested on authorization: wall for publishing, friends for friend access, email for email (separate, not always granted).
Token lifetime: up to 1 year or unlimited (depends on app type). Refresh token available in recent VKID versions—use to update without re-authorization.
VK API: Requests
All methods: https://api.vk.com/method/{method}?access_token=...&v=5.199. Pin API version—5.199 at time of writing. Without pinning, method behavior may change.
Get profile:
GET /method/users.get?fields=photo_200,city,bdate&v=5.199&access_token=...
Publish to wall:
POST /method/wall.post
{ message: "Post text", v: "5.199", access_token: "..." }
Get friends:
GET /method/friends.get?fields=photo_100,online,city&order=hints&count=100&v=5.199
Limits: 3 requests/second per token. Exceed—error code 6 (Too many requests). Use execute for batch (up to 25 methods per call).
Publishing Content
Publishing with photo requires two steps: photos.getWallUploadServer → POST to received URL → photos.saveWallPhoto → wall.post with attachments=photo{owner_id}_{photo_id}.
Common mistake: try to post image directly via wall.post. API doesn't work that way—photo must be pre-uploaded and saved.
Errors and Edge Cases
- Code 15: Access denied. User restricted data access in VK settings.
- Code 17: Captcha required. Rare on mobile apps, happens with bulk requests.
- Code 5: Invalid token. Expired or revoked—trigger re-authorization.
-
emailfield may be absent even withemailscope—VK only returns if user confirmed email.
Flutter
No official Flutter package from VK. Options: flutter_vk_sdk (community, not always updated) or implement OAuth flow yourself via flutter_web_auth_2 + direct HTTP to API. Second option more reliable—no package support dependency.
Timeline
VK ID authorization + profile import: 1–2 days. With media publishing: +1 day. Pricing calculated individually.







