D
D
Denny_Colt2017-08-03 08:21:58
Python
Denny_Colt, 2017-08-03 08:21:58

How to log in to VK using the vk api library?

I tried everything I could find on the internet.

import vk

app_id, login, password = '6126300', 'login', 'password'
session = vk.AuthSession(app_id, login, password, scope='messages')
vk_api = vk.API(session, v='5.67')
vk_api.wall.post(message="hello world")

It used to be possible to do it like this, but now it doesn't work either.
session = vk.Session(access_token='793ac3c7c978d96f8ea1357747393bad78836ac813e7217baa5b37b3111c16b13514d41026f183fc0b359')
api = vk.API(session)
api.wall.post(message="Hello, world")

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anatoly, 2017-08-03
@trofimovdev

Authorization is successful.
The error is that you are trying to write on the wall without certain permissions . In order to do this, you need to set permissions, wallor instead use a method that you have permissions to (based on the text of the question):api.wall.post(message="Hello, world")

api.messages.send(user_id=*любой_юзер*, message=*любое_сообщение*)

K
Konstantin Sazhenov, 2017-08-22
@sakost

There is an error in the library
You can write in PM , I can throw off a similar library, which
1) Authentication is 2 times faster
2) It takes much less space
And authentication by a login-password pair works (there is no need to parse pages, as vk does)
A in general, you can make a request like " https://oauth.vk.com/token?grant_type=password&pas... <password>&username=<login>&client_secret=<application secret>〈=ru&libverify_support=1&client_id=&2fa_supported=1&scope=all "
It will return {"access_token": '', "expire_in": "<how long the token will expire>"}

B
Baron Grafovich, 2020-01-22
@FlooJack

token = vk_api.VkApi(token = "")
vk = token.get_api()

vk.messages.send(user_id = "твой id", message = "Твой текст", random_id = 0)

IMPORTANT!!!!
To get a token you need to go to this site - https://vkhost.github.io/
and the login and password work only in certain cases, and they are limited!

D
deviur, 2020-02-10
@deviur

In the second example, the v argument is missing.
Should be: Instead of: It goes without saying that when receiving an access_token , rights must be obtained
vk_api = vk.API(session, v='5.67')
api = vk.API(session)
scope='wall'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question