如何使用 Telegram API 通过给定的 joinlink 获取私人频道的 chatid?
How to obtain chatid of a private channel by given joinlink using Telegram API?
我有一个这样的连接 link:https://t.me/joinchat/AAAAAEI95pT9clShebEcMg
我想知道获取那个频道chatid的函数
谢谢。
您可以使用电报 API 函数 messages.checkChatInvite
from telethon import TelegramClient
from telethon.tl.functions.messages.check_chat_invite import CheckChatInviteRequest
client = TelegramClient('session_id', '+phonenumber', api_id=1234, api_hash='0cxxxxxxx')
client.connect()
channel_hash = "AAAAAxxxxxxxx"
result = client.invoke(CheckChatInviteRequest(channel_hash))
print (result)
结果会是这样的:
(chatInviteAlready (ID: 0x5abcdefg) = (chat=(channel (ID: 0x5abcdefg) = (creator=None, kicked=None, left=None, editor=True, moderator=None, broadcast=True, verified=None, megagroup=None, restricted=None, democracy=None, signatures=None, min=None, id=123456789, access_hash=615xxxxxxxxx, title=testChannel, username=None, photo=(chatPhotoEmpty (ID: 0x37xxxxxxx) = ()), date=2017-06-14 14:34:50, version=0, restriction_reason=None))))
这里响应中的id就是你要找的频道id。
上面的例子是使用 Telethon 和 python,但你可以使用任何语言和客户端连接到电报 API。
我有一个这样的连接 link:https://t.me/joinchat/AAAAAEI95pT9clShebEcMg
我想知道获取那个频道chatid的函数
谢谢。
您可以使用电报 API 函数 messages.checkChatInvite
from telethon import TelegramClient
from telethon.tl.functions.messages.check_chat_invite import CheckChatInviteRequest
client = TelegramClient('session_id', '+phonenumber', api_id=1234, api_hash='0cxxxxxxx')
client.connect()
channel_hash = "AAAAAxxxxxxxx"
result = client.invoke(CheckChatInviteRequest(channel_hash))
print (result)
结果会是这样的:
(chatInviteAlready (ID: 0x5abcdefg) = (chat=(channel (ID: 0x5abcdefg) = (creator=None, kicked=None, left=None, editor=True, moderator=None, broadcast=True, verified=None, megagroup=None, restricted=None, democracy=None, signatures=None, min=None, id=123456789, access_hash=615xxxxxxxxx, title=testChannel, username=None, photo=(chatPhotoEmpty (ID: 0x37xxxxxxx) = ()), date=2017-06-14 14:34:50, version=0, restriction_reason=None))))
这里响应中的id就是你要找的频道id。 上面的例子是使用 Telethon 和 python,但你可以使用任何语言和客户端连接到电报 API。