Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to start? #133

Closed
ProgrammingLife opened this issue Feb 24, 2019 · 9 comments
Closed

How to start? #133

ProgrammingLife opened this issue Feb 24, 2019 · 9 comments

Comments

@ProgrammingLife
Copy link

I have "node v11.10.0" + MacOS 10.14.
Unfortunately I can't start VK-io because of these errors:

import VK from 'vk-io';
       ^^
SyntaxError: Unexpected identifier

...

import { VK } from 'vk-io';
       ^
SyntaxError: Unexpected token {

So I tried something else but again I've not succeed with that approach:

const vk = require('vk-io');
vk.token = "asdfasdfadsf";
const collectStream = vk.collect.wall.get({ owner_id: -86529522 });

// Error:
const collectStream = vk.collect.wall.get({
                                 ^
TypeError: Cannot read property 'wall' of undefined

What do I do wrong?

@negezor
Copy link
Owner

negezor commented Feb 24, 2019

The import works only with MJS, TypeScript or Babel preprocessing. Here you need to use Common JS:

const { VK } = require('vk-io');

const vk = new VK();
vk.token = 'asdfasdfadsf';

const collectStream = vk.collect.wall.get({ owner_id: -86529522 });

@ProgrammingLife
Copy link
Author

ProgrammingLife commented Feb 24, 2019

negezor, thanks! It works!
Do you happen to know why am I have such error?

vk.collectStream.on('error', console.error);
                 ^
TypeError: Cannot read property 'on' of undefined

I'm using up-to-date version of vk-io.

@negezor
Copy link
Owner

negezor commented Feb 25, 2019

Maybe the fact is that the vk object is used at the beginning?
Example for usage.

const collectStream = vk.collect.wall.get({ owner_id: -86529522 });

collectStream.on('error', console.error);

collectStream.on('data', payload => {
  console.log('Data', payload.items);
});
collectStream.on('end', () => {
	console.log('Data received');
});

@ProgrammingLife
Copy link
Author

Is there any little example on how to get messages from a wall of a group?
I'm new to VK service so it looks little bit confusing to me.
Which authorization method should I choose? What is the appId and the appSecret? I need to access to a group not to an application. Where can I pass my group's private Key?
I have a login/password data and the privateKey to the group. What should I do next?

@negezor
Copy link
Owner

negezor commented Feb 25, 2019

You can get posts from a group using the wall.get method, but it is not available for the group token. If there is a token, you need to using it only in the options.

const group = new VK({
  token: 'GROUP_TOKEN'
});

const app = new VK({
  token: 'APP_TOKEN_OR_USER_TOKEN'
});

// Method
app.api.wall.get({
  owner_id: -86529522 // Group ID
}); // => Promise

// Or collect all
app.collect.wall.get({
  owner_id: -86529522
}); // => CollectStream

The collection works with a user or application token. But only if the method supports.

@ProgrammingLife
Copy link
Author

ProgrammingLife commented Feb 25, 2019

Thanks!
What is the AppToken and where I get UserToken? Is it not the same as group's private key?

@negezor
Copy link
Owner

negezor commented Feb 26, 2019

Application token (Service Token). User token available via standalone or direct authorization. These are all tokens, have their permissions to call methods.

@ProgrammingLife
Copy link
Author

What token (and auth method) do I need to make wall.get requests?

My sample code now is:

const { VK } = require("vk-io");
const vk = new VK({ token: "...a long group API token placed here..." });
vk.api.wall.get({ owner_id: -86529522 });

But everytime I get a following message:
Code №5 - User authorization failed: method is unavailable with group auth.

Looks I can't just make simple wall.get request :)

@negezor
Copy link
Owner

negezor commented Feb 27, 2019

The method documentation indicates that it is not available for the group token. Need a service or user token, I already wrote about this above.
image

@negezor negezor closed this as completed Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants