The translation was generated automatically and may contain mistakes
Filed TO ID Captcha SDK Android
The Captcha SDK for Android contains the following classes, methods and interfaces:
- •
VKCaptchaSingleton class, the main entry point for displaying the captcha window, contains:- •
VKCaptcha.getToken()A method that returns a captcha success token. - •
VKCaptcha.openCaptcha()A method for displaying a captcha window. - •
VKCaptcha.closeCaptcha()A method for closing the captcha.
- •
- •
VKCaptchaResultListener- listener interface to track the result of passing the captcha. - •
VKCaptchaResult— sealed class, which describes the result of passing the captcha. - •
VKCaptchaErrorSealed class that describes a captcha error.
VKCaptcha
VKCaptcha Singleton class, the main entry point for the captcha window. Contains methods for opening and closing captchas.
object VKCaptcha {
fun openCaptcha() // открывает экран капчи
fun closeCaptcha() // закрывает экран капчи
fun getToken() // возвращает результат — токен успешного прохождения капчи
}VKCaptcha.getToken()
A method for obtaining a captcha pass token. The mobile application should call this method before each request to the server, in which the user needs to pass the captcha.
After successfully passing the captcha, the method returns the token you need to add to the API request in the header X-Challenge-Solution .
If there is no token, the method returns null . More specifically, in interaction scenarios .
object VKCaptcha {
fun getToken(domain: String): String? // возвращает токен успешного прохождения капчи
}VKCaptcha.openCaptcha()
A method for displaying a captcha window.
- •
urlTHE URL you received from the fieldredirect_uriduring processing captcha errors with code14or in conjunction withX-Challenge-Urlwith the domain — when processing headers. - •
listenerAn interface for tracking captcha resultsVKCaptchaResultListener. - •
domainThe domain where the captcha came from.
VKCaptcha.openCaptcha(domain, url, listener)VKCaptcha.closeCaptcha()
A method for closing the captcha.
VKCaptcha.closeCaptcha()VKCaptchaResultListener
Listener interface to track the result of passing the captcha.
Contains the method onResult(result: VKCaptchaResult) .
If the user cancels the passage of the captcha, inside onResult() The event will return VKCaptchaError.Cancelled .
interface VKCaptchaResultListener {
fun onResult(result: VKCaptchaResult) // результат прохождения капчи
}VKCaptchaResult
Sealed class, which describes the result of passing a captcha.
public sealed class VKCaptchaResult {
/** Успешное прохождение капчи */
public class Success internal constructor(
public val token: String, // success_token успешного прохождения капчи
public val domain: String?, // домен, при запросе к которому пришла капча
) : VKCaptchaResult()
/** Ошибка прохождения капчи */
public class Error internal constructor(
public val error: VKCaptchaError, // ошибка прохождения капчи (например, сетевая ошибка)
public val domain: String?, // домен, при запросе к которому пришла капча
) : VKCaptchaResult()
}VKCaptchaError
Sealed class, which describes a captcha error. Contains a stack trace, a sequence of method calls that resulted in an error, and a description:
- •Поле
messageAn error message. - •Поле
errora stack trace of an error: a description of the exception that caused the error, ornullif the cause of the error is not related to the exception.
Example code in case of a captcha error
public sealed class VKCaptchaError(
public val message: String, //сообщение об ошибке
public val error: Throwable?,
) {
/** Сетевые ошибки */
public class NetworkError internal constructor(
message: String,
error: Throwable? = null
) : VKCaptchaError(message, error)
/** Ошибки в параметра?1?… методов VK ID Captcha SDK*/
public class IllegalArgumentError internal constructor(
message: String
) : VKCaptchaError(message, IllegalArgumentException(message))
/** Если капча была закрыта до попытки её прохождения */
public class Cancelled internal constructor() : VKCaptchaError("You've cancelled the captcha flow", null)
}