P
P
prostiim2020-08-28 20:10:45
Python
prostiim, 2020-08-28 20:10:45

Is it possible to find chat_id using VK API?

Hello!

I have 100+ conversations on my account, is there any way to find out their chat_id and put it in a .txt file?

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WolfInChains, 2020-08-28
@prostiim

I recently made a similar script for myself, the current entry in json
Here is the code, you can do it for yourself
Before starting, create a file in the folder with the script data.jsonand fill it like this

{
  "conversations": [

  ]
}

The script itself
import vk_api
import json

vk_session = vk_api.VkApi(token='ТОКЕН')
vk = vk_session.get_api()

index = 1

while True:
    try:
        chat_info = vk.messages.getChat(chat_id=index)
        data = json.load(open('data.json', encoding='utf-8'))
        srt_info = {'title': f'{chat_info["title"]}', 'id': f'{chat_info["id"]}'}
        data['conversations'].append(srt_info)
        with open('data.json', 'w', encoding='utf-8') as file:
            json.dump(data, file, indent=2, ensure_ascii=False)
        file.close()
        index += 1
    except Exception as e:
        print(repr(e))

5f49452c03e43102713862.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question