我使用TLSharp来处理非常复杂的Telegram API。
很难理解如何将xxxAbswww
类型转换为包含真实可用信息的xxxwww
类型!
我有以下代码:
TLUser user = client.MakeAuthAsync("<user_number>", hash, code).Result;
如何获取经过身份验证的用户的照片?
答案 0 :(得分:2)
Agha Hamed,
可以使用'userProfilePhoto'电报方法访问用户的照片,而TLSharp没有实现此方法。
但是TLSharp提供了一些实现其他Telegram API方法的能力。他们说:
您可以在SendRequestAsync函数的帮助下调用任何方法。对于 例如,发送用户输入方法:
//Create request
var req = new TLRequestSetTyping()
{
action = new TLSendMessageTypingAction(),
peer = peer
};
//run request, and deserialize response to Boolean
return await SendRequestAsync<Boolean>(req);
不幸的是我不知道如何使用SendRequestAsync函数来执行此操作。
答案 1 :(得分:1)
尝试一下:
var photo = ((TLUserProfilePhoto)user.Photo);
var photoLocation = (TLFileLocation)photo.PhotoBig;
TLFile file = await client.GetFile(new TLInputFileLocation()
{
LocalId = photoLocation.LocalId,
Secret = photoLocation.Secret,
VolumeId = photoLocation.VolumeId
}, 1024 * 256);
//address to save pic
string fileName = "D:\\Project\\user_profile.jpg";
using (var m = new MemoryStream(file.Bytes))
{
var img = Image.FromStream(m);
//pictureBox1.Image = img; //make a preview
img.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
答案 2 :(得分:0)
我知道为什么没有TLSharp的例子! 如果您找到解决方案,我就像您一样,请在此发布 我刚刚发现TLUser有一个名为“photo”的方法