alexpods / meteor-accounts-vk

Login OAuth service for VKontakte accounts (https://vk.com)
MIT License
72 stars 21 forks source link

typeerror: cannot read property '0' of undefined #20

Open ivklgn opened 6 years ago

ivklgn commented 6 years ago

Package not compatible with vk API version 3. I had the following problem with mrt:accounts-vk. When I called Meteor.loginWithVk i received next error: Typeerror: cannot read property '0' of undefined.

This propblem associated with VK api version in getIdentity(accessToken) request. Steps for solve problem:

  1. In your meteor project create directory for local packages
  2. Clone https://github.com/alexpods/meteor-accounts-vk in /packages
  3. Rename package in this file: /packages/meteor-accounts-vk/package.js for example:
    Package.describe({
    summary: "Login service for VKontakte accounts (https://vk.com)",
    version: "0.2.0",
    git: "https://github.com/alexpods/meteor-accounts-vk",
    name: "mrt:accounts-vk2" // FIX NAME THERE
    });
  4. Install your local package locally. meteor add mrt:accounts-vk2 for prev example
  5. Fix VK API version in getIdentity (/packages/meteor-accounts-vk/lib/vk_server.js) Fixed example:
    ...
    var getIdentity = function (accessToken) {
    var result = HTTP.get(
        "https://api.vk.com/method/users.get", {params: {
            v: '3', // API VERSION
            access_token: accessToken,
            fields: 'uid, nickname, first_name, last_name, sex, bdate, timezone, photo, photo_big, city, country'
        }});
    ...

this is work for me.