首页 > 解决方案 > 从 stats channel request api telegram 获取数据

问题描述

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

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())```

标签: pythontelegramtelethon

解决方案


推荐阅读