简体   繁体   中英

How to get messages from a group chat on Telegram?

I am having trouble understanding the Telethon API in Python. I have created an account and have an api_id/api_hash, but I cannot connect to the server. This is what I have:

chat_id = "@thecointelegraph"
api_id = 'MYID'
api_hash = 'MYHASH'

client = TelegramClient('session_name',
                api_id,
                api_hash)
client.start()

I would like to download messages from a public telegram chat. Any help would be wonderful! Thank you!!

What is your current Code? How do you know you can't connect to the Server?

Usualy you would go about it kinda like this:

client = TelegramClient("username", "telegram_api", "api_hash")
client.start()
messages = client.get_message_history(dialog.entity, unread)

At least it was like this the last time, I used Telethon, I think by get_message_history was replaced by

get_messages()

https://lonamiwebs.github.io/Telethon/methods/messages/get_messages.html

Best thing to do is work yourself through the documentary: https://telethon.readthedocs.io/en/stable/index.html

from telethon import TelegramClient

entity = 'session'  # session_name
api_id = 123456
api_hash = '56bc70000yourhash'


client = TelegramClient(entity, api_id, api_hash)
client.start()

should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM