使用 TLSharp 如何获取 UserProfilePhoto 的照片?

Using TLSharp How to get UserProfilePhoto's photo?

我正在使用 TLSharp for dealing with really complicated Telegram API。

很难理解 xxxAbswww 类型如何转换为包含真正可用信息的 xxxwww 类型!

我有以下代码:

TLUser user = client.MakeAuthAsync("<user_number>", hash, code).Result;

如何获取认证用户的照片?

我不知道为什么没有 TLSharp 的例子! 我和你一样是新手,如果你找到了解决方案,请 post 在这里 我刚刚发现 TLUser 有一个名为 "photo"

的方法

阿迦·哈米德

可以使用 'userProfilePhoto' Telegram 方法访问用户的照片,而 TLSharp 未实现此方法。

但是 TLSharp 提供了一些功能来实现其他 Telegram API 方法。他们说:

You can call any method with help of SendRequestAsync function. For example, send user typing method:

  //Create request 
  var req = new TLRequestSetTyping()
  {
    action = new TLSendMessageTypingAction(),
    peer = peer
  };

  //run request, and deserialize response to Boolean
  return await SendRequestAsync<Boolean>(req);

很遗憾,我不知道如何使用 SendRequestAsync 函数来执行此操作。

试试这个:

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);
}