skip to Main Content

I’m using TLSharp for dealing with really complicated Telegram API.

it’s hard to understand how xxxAbswww types can be converted to xxxwww types which contains the real usable information!

I have the code below:

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

how can I get the photo of authenticated user?

3

Answers


  1. I dotn know why there is no example for TLSharp!
    i am a newbe like you if you found the solution please post it here
    i just discovered that TLUser has a method named “photo”

    Login or Signup to reply.
  2. Agha Hamed,

    Users’ photo is accessible using ‘userProfilePhoto’ Telegram method and TLSharp didn’t implemented this method.

    But TLSharp provided some fascilities to implement other Telegram API methods. They says:

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

    Unfortunately I don’t know how to use SendRequestAsync function to do this.

    Login or Signup to reply.
  3. try this:

    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);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search