对于我的英语不好和问题不清楚,我深表歉意。
我想下载电报频道或个人资料的照片。 所以我写这段代码:
此代码使用https://github.com/danog/MadelineProto库通过Telegram API进行文字编辑。
include __DIR__ . '/../app/Helper/madeline.php';
$settings = [
'app_info' => [ // Authorization settings
'api_id' => xxxxxxx,
'api_hash' => 'xxxxxxx',
'device_model'=>'Desktop',
'system_version'=>'18.0.4',
'app_version'=>'1.0',
'lang_code'=>'en',
]
];
$MadelineProto = new \danog\MadelineProto\API("$session.madeline", $settings);
$MadelineProto->start();
//get list of all channels, groups, chats, ...
$r = $MadelineProto->getDialogs();
dump($r);
$r2 = array_filter($r, function ($item){
return ($item['_']==='peerChannel');
});
$inputChannels = array_map(function($item){return 'channel#' . $item['channel_id'];}, $r2);
$channelsInfo = $MadelineProto->channels->getChannels(['id'=>$inputChannels]);
foreach ($channelsInfo['chats'] as $item) {
if($item['photo']['_']=== 'chatPhoto'){
$info = $MadelineProto->getPropicInfo($item);
dump($info);
$output_file_name = $MadelineProto->downloadToDir($info, __DIR__ . '/../public/mmedia/');
$image = '/public/mmedia/' . basename($output_file_name);
echo "<img src='$image' width='100%'>";
}
}
如何下载个人资料或频道的小照片?
文档中仅提供有关getPropicInfo
方法的一些信息。
我认为根据channels->getChannels
结果的这一部分有一些小照片:
...
"photo" => array:4 [▼
"_" => "chatPhoto"
"photo_small" => array:3 [▼
"_" => "fileLocationToBeDeprecated"
"volume_id" => 428929657
"local_id" => 311720
]
"photo_big" => array:3 [▼
"_" => "fileLocationToBeDeprecated"
"volume_id" => 428929657
"local_id" => 311722
]
"dc_id" => 4
]
...
感谢您的回复。