K
K
Killerqu002019-01-15 20:54:09
Python
Killerqu00, 2019-01-15 20:54:09

Accessing conversations via VkApi on behalf of the community - how to implement?

import vk_api
import requests
import json
import vk
token = 'токен'
confaid = 2000000001
session = vk_api.VkApi(token=token)
def getlastmsg(confa, token):
    payload = {'access_token':token, 'peer_id':confa, 'count':1}
    r = requests.get('https://api.vk.com/method/messages.getHistory?v=5.52', params = payload)
    txt = r.text
    data = json.loads(txt)
    print(r.url)
    return data['response']['items'][0]['body']
def cmdpart(stroka, number):
    stroka0 = stroka.split()
    try:
        return stroka0[number]
    except IndexError:
        return 'Ошибка, скорее всего, недостаточно аргументов'
print(getlastmsg(confaid, token))

I tried this code, but it returns a KeyError when I try to return a value in getlastmsg. I generated a link, and it gave me this thing:
{"error":{"error_code":15,"error_msg":"Access denied","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"messages.getHistory"},{"key":"v","value":"5.52"},{"key":"peer_id","value":"2000000001"},{"key":"count","value":"1"}]}}

Perhaps, on behalf of the community, the conversations should be addressed in a different way?
Ps The community added to the conversation, gave access to all correspondence.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-01-15
@Killerqu00

messages.getHistory doesn't work on behalf of the community in conversations
using the Bots LongPoll API or Callback API

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question