Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
com.vk:androidsdkapi
Advanced tools
VK Android API generated library(deprecated will be removed since 01.09.2021)
Library for working with VK API, authorization through VK app, using VK functions. Minimal version of Android is 5.0
To use VK SDK primarily you need to create a new VK application here by choosing the Standalone application type. Choose a title and confirm the action via SMS and you will be redirected to the application settings page. You will require your Application ID (referenced as API_ID in the documentation). Fill in the "Batch name for Android", "Main Activity for Android" and "Certificate fingerprint for Android".
To receive your certificate's fingerprint you can use one of the following methods.
The keystore for the release version is usually created by a programmer, so you should create it or recall its location.
keytool -exportcert -alias androiddebugkey -keystore path-to-debug-or-production-keystore -list -vYou will observe a similar result:
Certificate fingerprint: SHA1: DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09By deleting all the colons you'll get your key's fingerprint.
If you've already added SDK to your project, you can use the following function in each Activity of your app.
String[] fingerprints = VKUtils.getCertificateFingerprint(this, this.getPackageName());
As a rule, fingerprints contains a single line. It's a fingerprint of your certificate (depends on the certificate used for your app's signing)
Click in right menu on Gradle tab (or double shift and type Gradle). Open your project root folder, then open Tasks and after android. Run signingReport task. Find your SHA1 fingerprint in Run tab output.
You can add more than one fingerprint in your app settings, e.g., debug and release fingerprints.
You can add next maven dependency in your project:
The available library modules are listed below.
android-sdk-core
: Core functionality (required).
android-sdk-api
: Api generated models and methods.
androidsdk
: deprecated copy version of the android-sdk-core(will be removed in future releases since 01.09.2021).
androidsdkapi
: deprecated copy version of the android-sdk-api(will be removed in future releases since 01.09.2021).
For example, your app/build.gradle
script will contains such dependencies:
dependencies {
implementation 'com.vk:android-sdk-core:3.x.x
implementation 'com.vk:android-sdk-api:3.x.x // generated models and api methods
}
<uses-permission android:name="android.permission.INTERNET"/>
<integer name="com_vk_sdk_AppId">your_app_id</integer>
Use VK.login method:
VK.login(activity, arrayListOf(VKScope.WALL, VKScope.PHOTOS))
Override onActivityResult:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val callback = object: VKAuthCallback {
override fun onLogin(token: VKAccessToken) {
// User passed authorization
}
override fun onLoginFailed(errorCode: Int) {
// User didn't pass authorization
}
}
if (data == null || !VK.onActivityResult(requestCode, resultCode, data, callback)) {
super.onActivityResult(requestCode, resultCode, data)
}
}
Create instance of VKTokenExpiredHandler:
class SampleApplication: Application() {
override fun onCreate() {
super.onCreate()
VK.addTokenExpiredHandler(tokenTracker)
}
private val tokenTracker = object: VKTokenExpiredHandler {
override fun onTokenExpired() {
// token expired
}
}
}
Run request with VK.execute and auto generated methods(android-sdk-api dependency is required):
VK.execute(FriendsService().friendsGet(fields = fields), object: VKApiCallback<FriendsGetFieldsResponse> {
override fun success(result: FriendsGetFieldsResponse) {
// you stuff is here
}
override fun fail(error: Exception) {
Log.e(TAG, error.toString())
}
})
If you are using RxJava in your project, you can do something like this:
Observable.fromCallable {
VK.executeSync(VKUsersRequest())
}
.subscribeOn(Schedulers.single())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
// response here
}, {
// throwable here
})
If you need more complex request, you should override ApiCommand. This approach allows you to make multiple requests at once For example: VKUsersRequest
class VKUsersCommand(private val uids: IntArray = intArrayOf()): ApiCommand<List<VKUser>>() {
override fun onExecute(manager: VKApiManager): List<VKUser> {
if (uids.isEmpty()) {
// if no uids, send user's data
val call = VKMethodCall.Builder()
.method("users.get")
.args("fields", "photo_200")
.version(manager.config.version)
.build()
return manager.execute(call, ResponseApiParser())
} else {
val result = ArrayList<VKUser>()
val chunks = uids.toList().chunked(CHUNK_LIMIT)
for (chunk in chunks) {
val call = VKMethodCall.Builder()
.method("users.get")
.args("user_ids", chunk.joinToString(","))
.args("fields", "photo_200")
.version(manager.config.version)
.build()
result.addAll(manager.execute(call, ResponseApiParser()))
}
return result
}
}
companion object {
const val CHUNK_LIMIT = 900
}
private class ResponseApiParser : VKApiResponseParser<List<VKUser>> {
override fun parse(response: String): List<VKUser> {
try {
val ja = JSONObject(response).getJSONArray("response")
val r = ArrayList<VKUser>(ja.length())
for (i in 0 until ja.length()) {
val user = VKUser.parse(ja.getJSONObject(i))
r.add(user)
}
return r
} catch (ex: JSONException) {
throw VKApiIllegalResponseException(ex)
}
}
}
}
VKUsersCommand supports dividing by chunks for working with api limits. This is main difference between VKUsersRequest and VKUsersCommand
Also you can check up VKWallPostCommand. This an example of complex api request with file uploading
FAQs
VK Android API generated library(deprecated will be removed since 01.09.2021)
We found that com.vk:androidsdkapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.