从stats通道请求api电报获取数据

2024-05-28 21:17:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从电报api获取统计数据通道。我编写并运行了此代码,但出现错误: telethon.errors.rpcerrorlist.ChatAdminRequiredError:在指定的聊天中执行此操作需要聊天管理员权限(例如,在非您的频道中发送消息),或者权限无效 用于频道或组的s(由GetBroadcasts StatsRequest引起) 请帮我检查并修理一下。非常感谢! 这是我的频道

import configparser
from telethon.tl.types import ChannelParticipantsSearch
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon import functions, types
from telethon.tl.functions.stats import GetBroadcastStatsRequest
from telethon.tl.types import PeerUser, PeerChat, PeerChannel
from telethon.tl.types import InputChannel
config = configparser.ConfigParser()
config.read("config.ini")


api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']

api_hash = str(api_hash)

phone = config['Telegram']['phone']
username = config['Telegram']['username']
channel = 'https://t.me/testapi2607'
id_channel = 1523534046
access_hash = 7456721436474437
client = TelegramClient(username, api_id, api_hash)
async def main():
    await client.start()
    print("Client Created")
    # Ensure you're authorized
    if await client.is_user_authorized() == False:
        await client.send_code_request(phone)
        try:
            await client.sign_in(phone, input('Enter the code: '))
        except SessionPasswordNeededError:
            await client.sign_in(password=input('Password: '))
    me = await client.get_me()
    await client.get_entity(PeerChannel(1523534046))
    my_channel = InputChannel(id_channel, access_hash)
    result = await client(functions.stats.GetBroadcastStatsRequest(channel = my_channel, dark=True))
    print(str(result))
with client:
    client.loop.run_until_complete(main())```

Tags: fromimportclientapiidconfigchannelphone

热门问题