问题描述
我想在电报中记录所有聊天参与者的昵称和照片。为此,我有这样的代码:
client = TelegramClient(username,api_id,api_hash)
async def dump_all_participants(channel) -> list:
offset_user = 0
limit_user = 100
all_participants = []
filter_user = ChannelParticipantsSearch('')
while True:
participants = await client(GetParticipantsRequest(channel,filter_user,offset_user,limit_user,hash=0))
if not participants.users:
break
all_participants.extend(participants.users)
offset_user += len(participants.users)
all_users_details = []
for participant in all_participants:
if participant.photo is None:
photo = UNKNowN.STRING
else:
photo = participant.photo
all_users_details.append({participant.id: [participant.username,photo]})
return all_users_details
问题在于照片是Telethon对象。我无法取出照片,也不知道该怎么做
输出照片:UserProfilePhoto(photo_id=208135253786732667,photo_small=FileLocationTobedeprecated(volume_id=257125342,local_id=230348),photo_big=FileLocationTobedeprecated(volume_id=257125342,local_id=230350),dc_id=2,has_video=False)
我在文档documentation InputPhoto中找到了InputPhoto,希望对我有帮助,但是文档中没有使用示例,我无法弄清楚如何实现它。有人可以帮忙提供提示或示例,以获取照片吗?
解决方法
telethon中有解决此问题的方法:download_profile_photo
您可以将照片下载或存储在内存中以供以后使用。