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:

VKCaptcha

VKCaptcha Singleton class, the main entry point for the captcha window. Contains methods for opening and closing captchas.

Kotlin
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 .

Kotlin
object VKCaptcha { fun getToken(domain: String): String? // возвращает токен успешного прохождения капчи }

VKCaptcha.openCaptcha()

A method for displaying a captcha window.

  • •
    url THE URL you received from the field redirect_uri during processing captcha errors with code 14 or in conjunction with X-Challenge-Url with the domain — when processing headers.
  • •
    listener An interface for tracking captcha results VKCaptchaResultListener .
  • •
    domain The domain where the captcha came from.
Kotlin
VKCaptcha.openCaptcha(domain, url, listener)

VKCaptcha.closeCaptcha()

A method for closing the captcha.

Kotlin
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 .

Kotlin
interface VKCaptchaResultListener { fun onResult(result: VKCaptchaResult) // результат прохождения капчи }

VKCaptchaResult

Sealed class, which describes the result of passing a captcha.

Kotlin
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:

  • •
    Поле message An error message.
  • •
    Поле error a stack trace of an error: a description of the exception that caused the error, or null if the cause of the error is not related to the exception.

Example code in case of a captcha error

Kotlin
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) }