D
D
Dmitry Prilepsky2020-08-27 17:23:59
Python
Dmitry Prilepsky, 2020-08-27 17:23:59

How to use InputPhoto in telethone?

I have a photo id and I need to pull it out of telegram. I use telethon, but its documentation is hell. I really tried to understand, but without examples it is very difficult. Please help with an example (or at least advice where to look for it). I made this myself

def get_data(user):
  with TelegramClient('anon', api_id, api_hash) as client:
      result = client(functions.photos.GetUserPhotosRequest(
          user_id=user,
          offset=0,
          max_id=0,
          limit=0
      ))
      client.flood_sleep_threshold = 24 * 60 * 60 
      array_of_photos = result.photos
      for photo in array_of_photos:
      	file_reference = photo.file_reference
      	file_id = photo.id
      	access_hash = photo.access_hash
      	return file_reference, file_id, access_hash
    	



file_reference, file_id, access_hash = get_data('user')



with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.upload.GetFileRequest(
        location=types.InputFileLocation(
            volume_id=-12398745604826,
            local_id=42,
            secret=-12398745604826,
            file_reference=b'arbitrary\x7f data \xfa here'
        ),
        offset=42,
        limit=100,
        precise=True,
        cdn_supported=True
    ))
    print(result.stringify())

But it refuses to work. I also tried to use the input photo itself, but telethon swears and says that types cannot be called

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emil Timerbaev, 2020-08-27
@MrDlop

How to download a photo sent by telegram bot?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question