Skip to content
forked from v12/node-vk-api

Wrapper for using VK API within your project as a Standalone application

Notifications You must be signed in to change notification settings

2byte/node-vk-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vk-dirty-api

VK API for Node.js with authentication using login and password (the dirty way)

Sometimes it is needed to use VK API directly from the Node app, however, using either signing requests or OAuth allows access only to server-side methods. In order to 'overcome' this limitation, this dirty if you know what I mean way of getting access_token for VK API was developed

Installation

$ npm install vk-dirty-api

Usage

Super simple to use

var vkApi = require('vk-dirty-api');

var credentials = {
    client_id: 0,
    login:     'user@example.com', // could be phone number as well
    pass:      'your_super_secret_password'
};

var vk = new vkApi(
    credentials,
    function (err, access_token) {
        if(err)
            return console.error('Unable to authenticate', err);
        console.log('Successfully authenticated / access_token:', access_token);
    });
    
vk.on('auth', function (token) {
    vk.api('users.get', { user_ids: 1 }, function (err, info) {
        if(err)
            return console.error('Unable to complete request', err);
        console.log(info);
    });
});

vk.on('error', function (err) {
    // do authentication fail related stuff... 
});

Methods

vk.api(method, [ options ], callback)

  • method String API method that you are willing to use for the request (see VK Platform Documentation)
  • options Object Fields that will be passed to VK with the used API method
  • callback Function -

Events

Event: 'auth'

  • token String Access token that is required for future requests
  • expires_in Number Amount of time (seconds) after which this access token will expire This event is emitted when authorization is successful and access token is returned

Event: 'error'

  • error Error This event is triggered when error happens when initializing VK API.

Dependencies

  • request - making requests to VK API
  • cheerio - parsing auth pages
  • xtend - extending JavaScript objects

Changelog

  • 1.0.0 - added another way of instantiating API (both parameter sets are available)
  • 0.0.3 - VK API response is now properly parsed, returning Error in callback with error code and description when method execution has failed (list of API errors)
  • 0.0.2 - constructor now emits events on successful authorization and error

ToDo

  • Error handling
    • Error on authorization fail
    • Handling error in API response
    • Invalid parameters usage in module methods
  • Caching access_token
  • Choosing the version of VK API to use in requests

About

Wrapper for using VK API within your project as a Standalone application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%