Skip to content

Latest commit

 

History

History
200 lines (119 loc) · 7.01 KB

File metadata and controls

200 lines (119 loc) · 7.01 KB

Driver API

vk.getAuthUrl([appId=vk.appId], [permissions=[]], [options={}])

Suggests a URL for app authentication. See Client Application Authorization.

This method is an optional utility. Skip it if you use a different auth flow or prefer to create a custom auth URL.

Since: 0.1.0

Arguments
  1. [appId=vk.appId] (number|string): ID of your VK application. See My Applications.
  2. [permissions=[]] (Array): Permissions for your VK application. See My Applications.
  3. [options.version="5.53"] (string): API version to use when calling api.vk.com. vk.version is set to this value and used in other methods.
  4. [options.redirectUrl="https://oauth.vk.com/blank.html"] (string): URL to which the auth window will be redirected after authentication.
  5. [options.windowStyle="popup"] (string): Auth window style. See OAuth Authorization Dialog.
Returns

(string): Returns a URL to use in window.open().

Examples
vk.getAuthUrl("12345", ["audio", "photos"], {version: "4.10"})
// "https://oauth.vk.com/authorize?client_id=12345&scope=audio,photos&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&display=popup&v=4.10&response_type=token"

vk.getAuthUrl("12345", ["friends"], vk.version, {windowStyle: "page"})
// "https://oauth.vk.com/authorize?client_id=12345&scope=friends&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&display=page&v=5.53&response_type=token"

vk.appId = "12345"
vk.getAuthUrl()
// "https://oauth.vk.com/authorize?client_id=12345&scope=&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&display=popup&v=5.53&response_type=token"

vk.authWebsite([appId=vk.appId], [permissions=[]], [windowStyle="popup"], [callback=noop])

Authenticates an app on a website via a popup and obtains an access token. See Client Application Authorization and Open API.

Doesn't open a popup if the app is already authenticated. You don't need to call vk.getAccessToken() before vk.authWebsite() to check this.

This method is an optional utility. Skip it if you use a different auth flow or prefer to obtain an access token yourself.

This method sets vk.accessToken automatically. If you skip this method, set vk.accessToken to your token before using the API.

Since: 0.3.0

Arguments
  1. [appId=vk.appId] (number|string): ID of your VK application. See My Applications.
  2. [permissions=[]] (Array): Permissions for your VK application. See My Applications.
  3. [options.windowStyle="popup"] (string): Auth window style. See OAuth Authorization Dialog.
  4. [callback=noop] (Function|null): optional callback with signature callback(accessToken).
Returns

(Promise): Resolves with an access token to use when calling API.

Examples
vk.authWebsite("12345").then(function(token) {
  console.log(token) // "6a7ccc59b984856dc1424ef..."
})

vk.authWebsite("12345", ["audio", "photos"], "page", function(token) {
  console.log(token) // "6a7ccc59b984856dc1424ef..."
})

vk.appId = "12345"
vk.authWebsite().then(function(token) {
  console.log(token) // "6a7ccc59b984856dc1424ef..."
})

vk.getAccessToken([appId=vk.appId], [callback=noop])

Obtains an access token from https://login.vk.com/ after the app has been authenticated. See Client Application Authorization and Open API.

This method is an optional utility. Skip it if you use a different auth flow or prefer to obtain an access token yourself.

This method sets vk.accessToken automatically. If you skip this method, set vk.accessToken to your token before using the API.

Since: 0.2.0

Arguments
  1. [appId=vk.appId] (number|string): ID of your VK application. See My Applications.
  2. [callback=noop] (Function|null): optional callback with signature callback(accessToken).
Returns

(Promise): Resolves with an access token to use when calling API.

Examples
vk.getAccessToken("12345").then(function(token) {
  console.log(token) // "6a7ccc59b984856dc1424ef..."
})

vk.getAccessToken("12345", function(token) {
  console.log(token) // "6a7ccc59b984856dc1424ef..."
})

vk.appId = "12345"
vk.getAccessToken().then(function(token) {
  console.log(token) // "6a7ccc59b984856dc1424ef..."
})

vk.method(methodName, [params={}], [callback=noop])

Calls the specified API method and returns its result. See API Requests.

Supports both callbacks and promises.

This method uses vk.request() for performing actual network requests. Override vk.request to change the behavior of this library.

Since: 0.1.0

Arguments
  1. methodName (string): the name of the API method. See API Methods.
  2. [params={}] (Object): Parameters to pass to the API.
  3. [callback=noop] (Function|null): optional callback with signature callback(error, response).
Returns

(Promise): Resolves with the result from the API or rejects with the error if it exists.

Examples
vk.accessToken = "your-token"

vk.method("users.get", {fields: "online"}).then(function(result) {
  console.log(result.online)

}, function(error) {
  console.log(error)
})

vk.method("users.get", {fields: "online"}, function(error, result) {
  console.log(error || result.online)
})

Aliases

The vk object has built-in aliases for most API methods. Each alias is a transparent wrapper around vk.method.

For an exhaustive list of available aliases please refer to src/method-list.coffee.

Since: 0.1.0

Arguments
  1. params (Object): Parameters to pass to the API.
  2. [callback=noop] (Function|null): optional callback with signature callback(error, response).
Returns

(Promise): Returns a promise that resolves with a result from the API or rejects with an error if it exists.

Examples
vk.accessToken = "your-token"

vk.users.get({fields: "online"}).then(function(result) {})
// Same as vk.method("users.get", ...)

vk.execute({...}, function(error, result) {})
// Same as vk.method("execute", ...)