4

In an app, we need to import contacts of a user. We found Telegram.Link which implements Telegram API. It has a method that retrieves contacts. A single contact is showed below:

{
T: api.type.UserContact,
id: 148049613,
first_name: "M.",
last_name: "Barezban",
username: "Barezban",
access_hash: "0x47ad17f617b9e945",
phone: "989363356056",
photo: {
  T: api.type.UserProfilePhoto,
  photo_id: "0x08d30ecd1b31a7bc",
  photo_small: {
    T: api.type.FileLocation,
    dc_id: 4,
    volume_id: "0x00000000192931a8",
    local_id: 75848,
    secret: "0xac6db13d308318b3"
  },
  photo_big: {
    T: api.type.FileLocation,
    dc_id: 4,
    volume_id: "0x00000000192931a8",
    local_id: 75850,
    secret: "0x4f302deb78247cce"
  }
},
status: {
  T: api.type.UserStatusOffline,
  was_online: 1463043346
}}

I found no way to download the profile photo. which method should I use?

I tried python-telegram-bot which implements Telegram Bot API and has two method that could help me: getUserProfilePhotos and getFile.

I tried bot.getUserProfilePhotos(148049613) and got telegram.error.NetworkError: Bad Request: user not found (400).

I also tried bot.getFile('0x08d30ecd1b31a7bc') and got telegram.error.NetworkError: Bad Request: invalid file id (400)

There is also a method named upload.getFile that uses volume_id, local_id and secret but I don't know how to use and call this method.

So how can I download this photo?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
omid
  • 63
  • 1
  • 11

1 Answers1

0

File download in Telegram API is done via:

upload.getFile#e3a6cfb5 location:InputFileLocation offset:int limit:int = upload.File;

See upload.getFile as well as https://core.telegram.org/api/files#downloading-files

NOTE some of those API Types there are outdated (look here for the latest), but the gist of how file downloads work is explained there.

You have everything you need. In most cases you can download profile pictures with just one call to upload.getFile (up to 512 Kb). The link above gives clear details.

1)For InputFileLocation use

api.type.FileLocation{
   dc_id: 4,
   volume_id: "0x00000000192931a8",
   local_id: 75850,
   secret: "0x4f302deb78247cce"}

2) For offset use: 0

3) For limit use: 0

Note that you need to send this from the proper connection, in this case a connection to dc_id = 4, to avoid

{error_code: 303, error_message: "USER_MIGRATE_4" / "FILE_MIGRATE_4"}  
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157
  • Thanks for answer. Do you know any implementation of this method in python or meteor(Node.js)? – omid May 18 '16 at 13:22
  • @omid Sorry, I don't code much python. but is this not included in your telegram.link? you can extend the GitHub repo to do this, yes? – Charles Okwuagwu Jun 24 '16 at 21:42