Skip to content

Latest commit

 

History

History
163 lines (102 loc) · 4.33 KB

File metadata and controls

163 lines (102 loc) · 4.33 KB

React-native wrapper around vk-ios-sdk and vk-android-sdk Provides login and share functionality

Index


Methods

initialize

initialize(vkAppId: numberstring): void

Initializes VK SDK from JS code. You only need to call this once before you call login or logout. You can skip this call if you've added your VK App ID to your Android's resources or iOS's info.plist.

Parameters:

Param Type Description
vkAppId numberstring Your VK app id

Returns: void


isLoggedIn

isLoggedIn(): Promise<boolean>

Checks if user is already logged in.
This means that access token exists and is not expired.

Returns: Promise<boolean> Promise that resolves with boolean value


getAccessToken

getAccessToken(): Promise<VKLoginResult | null>

Returns VK access token (if it exists)

Returns: Promise<boolean> Promise that resolves with VKLoginResult (access token) or null


login

login(scopesArray: string[]): Promise<VKLoginResult>

Opens VK login dialog either via VK mobile app or via WebView (if app is not installed on the device). If the user is already logged in and has all the requested permissions, then the promise is resolved straight away, without VK dialog.

Parameters:

Param Type Description
scopesArray string[] array which contains VK access permissions as strings,e.g. ['friends', 'photos', 'email']List of available permissions can be found here

Returns: Promise<VKLoginResult> Promise will be resolved with VKLoginResult object


logout

logout(): Promise<void>

Performs the logout

Returns: Promise<void> empty promise


share

share(options: VKShareOptions): Promise<number>

Opens VK share dialog either via VK mobile app or via WebView (if app is not installed on the device). Make sure to have correct permissions!

Parameters:

Param Type Description
options VKShareOptions VKShareOptions object

Returns: Promise<number> Promise that resolves with postId number


getCertificateFingerprint

getCertificateFingerprint(): Promise<string[]>

Android only - helper method to get fingerprints on JS side

Returns: Promise<string[]> Promise that resolves with array of string fingerprints


Interface: VKLoginResult

Response from login method

Property Type Description
access_token stringnull String token for use in request parameters
email stringnull User email, or null, if permission was not given
expires_in numberundefined Time when token expires
https_required booleanundefined Android only If user sets "Always use HTTPS" setting in his profile, it will be true
secret stringnull User secret to sign requests (if nohttps used)
user_id stringnull Current user id for this token

Interface: VKShareOptions

Share dialog options

Property Type Description
description stringundefined Shared text message
image numberundefined Shared image, local file resource, i.e. require('path/to/your/image.png')
linkText stringundefined Shared link name
linkUrl stringundefined Shared link URL

Enum constant: VKError

Constant ot compare error codes of rejected promises

Common errors:

  • VKError.E_NOT_INITIALIZED
  • VKError.E_VK_UNKNOWN
  • VKError.E_VK_API_ERROR
  • VKError.E_VK_CANCELED
  • VKError.E_VK_REQUEST_NOT_PREPARED

iOS specific errors:

  • VKError.E_VK_RESPONSE_STRING_PARSING_ERROR
  • VKError.E_VK_AUTHORIZE_CONTROLLER_CANCEL

Android specific errors:

  • VKError.E_VK_JSON_FAILED
  • VKError.E_VK_REQUEST_HTTP_FAILED
  • VKError.E_ACTIVITY_DOES_NOT_EXIST
  • VKError.E_FINGERPRINTS_ERROR