57uff3r / nodejs-vksdk

NodeJS SDK for vk.com
201 stars 82 forks source link

users.get returns undefined #30

Closed LightVolk closed 8 years ago

LightVolk commented 8 years ago
console.log('Hello world!!!!');
var VK = require('vksdk');

var vk = new VK({

    'appId' : 1233456,
    'appSecret': 'secret',    

});

function getProfile(uid) {
    vk.request('users.get', { 'user_ids': uid });
    vk.on('done:users.get', function (_o) {

        return _o;
    });
}

vk.setSecureRequests(false);

var profile = getProfile(1);

console.log(profile);

Can you help me- why result if undefined?

57uff3r commented 8 years ago

Should be like this


      vk.request('users.get', {'user_id' : 1}, function(_o) {
        //console.log(_o);
        assert.equal(_o.response[0].id,  1);
        assert.ok(['Павел', 'Pavel'].indexOf(_o.response[0].first_name) !== -1);
        assert.ok(['Дуров', 'Durov'].indexOf(_o.response[0].last_name) !== -1);
        done();
      });

And make sure you setup correct app id and secret.