B
B
Bexruz Sayfiddinov2021-03-26 19:17:39
Facebook
Bexruz Sayfiddinov, 2021-03-26 19:17:39

How to get file id (audio id) from channel tg using telethon?

the code itself

import json
from datetime import datetime
from telethon.tl import functions
from telethon.sync import TelegramClient


import threading
import sqlite3 as sql


api_id = .....
api_hash = ""

link = 'https://t.me/wallpaper_4k3d'

day = 25
mon = 3
year = 2021

client = TelegramClient('client', api_id, api_hash)
client.connect()


result = client(functions.messages.GetHistoryRequest(
                            peer=link,
                            offset_id=0,
                            offset_date=datetime(year, mon, day),
                            add_offset=0,
                            limit=1,
                            max_id=0,
                            min_id=0,
                            hash=0
                        ))

# print(len(result.messages))
print(result.stringify())


client.start()
client.run_until_disconnected()


and json
ChannelMessages(
  pts=21863,
  count=8962,
  messages=[
    Message(
      id=11828,
      peer_id=PeerChannel(
        channel_id=1192633426
      ),
      date=datetime.datetime(2021, 3, 24, 20, 1, 54, tzinfo=datetime.timezone.utc),
      message='',
      out=False,
      mentioned=False,
      media_unread=False,
      silent=True,
      post=True,
      from_scheduled=False,
      legacy=False,
      edit_hide=False,
      pinned=False,
      from_id=None,
      fwd_from=None,
      via_bot_id=None,
      reply_to=None,
      media=MessageMediaDocument(
        document=Document(
          id=5972261332005685336,
          access_hash=-443478324099976471,
          file_reference=b'\x02G\x16$R\x00\x00.4`^\x07\x0b\x892\x89m\xdazr\xd9\xa0\xf2\xcd\x16\x83\xe6\tx',
          date=datetime.datetime(2021, 3, 24, 19, 52, 45, tzinfo=datetime.timezone.utc),
          mime_type='image/jpeg',
          size=12076458,
          dc_id=4,
          attributes=[
            DocumentAttributeFilename(
              file_name='@Wallpaper_4K3D (5200).jpg'
            ),
          ],
          thumbs=[
          ],
          video_thumbs=[
          ]
        ),
        ttl_seconds=None
      ),
      reply_markup=None,
      entities=[
      ],
      views=31235,
      forwards=602,
      replies=None,
      edit_date=None,
      post_author=None,
      grouped_id=12932928914997036,
      restriction_reason=[
      ],
      ttl_period=None
    ),
  ],
  chats=[
    Channel(
      id=1192633426,
      title='Wallpaper 4K 3D | والپیپر | Обои',
      photo=ChatPhoto(
        photo_small=FileLocationToBeDeprecated(
          volume_id=455136452,
          local_id=458191
        ),
        photo_big=FileLocationToBeDeprecated(
          volume_id=455136452,
          local_id=458193
        ),
        dc_id=4,
        has_video=False
      ),
      date=datetime.datetime(2020, 1, 16, 15, 44, 12, tzinfo=datetime.timezone.utc),
      version=0,
      creator=False,
      left=True,
      broadcast=True,
      verified=False,
      megagroup=False,
      restricted=False,
      signatures=False,
      min=False,
      scam=False,
      has_link=False,
      has_geo=False,
      slowmode_enabled=False,
      call_active=False,
      call_not_empty=False,
      fake=False,
      gigagroup=False,
      access_hash=-5167254645334825439,
      username='wallpaper_4k3d',
      restriction_reason=[
      ],
      admin_rights=None,
      banned_rights=None,
      default_banned_rights=None,
      participants_count=None
    ),
  ],
  users=[
    User(
      id=136817688,
      is_self=False,
      contact=False,
      mutual_contact=False,
      deleted=False,
      bot=True,
      bot_chat_history=False,
      bot_nochats=False,
      verified=False,
      restricted=False,
      min=False,
      bot_inline_geo=False,
      support=False,
      scam=False,
      apply_min_photo=True,
      fake=False,
      access_hash=2139013343945445059,
      first_name='Channel',
      last_name=None,
      username='Channel_Bot',
      phone=None,
      photo=UserProfilePhoto(
        photo_id=587627495930570665,
        photo_small=FileLocationToBeDeprecated(
          volume_id=702424587,
          local_id=39096
        ),
        photo_big=FileLocationToBeDeprecated(
          volume_id=702424587,
          local_id=39098
        ),
        dc_id=1,
        has_video=False
      ),
      status=None,
      bot_info_version=4,
      restriction_reason=[
      ],
      bot_inline_placeholder=None,
      lang_code=None
    ),
  ],
  inexact=False,
  offset_id_offset=49
)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Philipp, 2018-03-25
@lexstile

It is recommended to configure https ://developers.facebook.com/docs/facebook-logi...
Moreover, it is easy to do and you do not need to buy anything https://habrahabr.ru/post/318952/

E
Ernest Faizullin, 2018-03-25
@erniesto77

most likely in the developers.facebook.com panel in the application settings you have force ssl, uncheck it
is not necessary to buy from there. All applications work on http

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question