CopyPastor

Detecting plagiarism made easy.

Score: 0.8371159434318542; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2024-02-08
by Mahozad

Original Post

Original - Posted on 2022-08-07
by Mahozad



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can use the other type of Telegram API: [Telegram \[client\] API and TDLib](https://core.telegram.org/#tdlib-build-your-own-telegram)
Using [telethon library][1] makes it easy to read channels history (see [telethon docs][2]).
For this, we need an `api_id` and an `api_hash`. So, do the following:
1. Log in to [Telegram core](https://my.telegram.org/) 2. Open the [API development tools area](https://my.telegram.org/apps) 3. Fill out the simple form there 4. Now you can receive your `api_id` and `api_hash` <sub>For more information, see Telegram's help documentation about [how to get your API credentials](https://core.telegram.org/api/obtaining_api_id).</sub>
Here is an example code that gets the last *5* messages of *targetChannelId*:
```python from telethon import TelegramClient

API_ID = 123456 # See above for how to get it API_HASH = '123abc' # See above for how to get it client = TelegramClient('my-client', API_ID, API_HASH)

async def main(): async for message in client.iter_messages('targetChannelId', limit=5): print(message.id, message.text)

with client: client.loop.run_until_complete(main()) ```
The first time you run this code it asks your phone number or bot token. Enter your **phone number** in the format `+9912345...` where `99` is your country code and the rest is your phone number. It then may send a login code to your Telegram app; enter it in the console.
**Note**: Only users (phone numbers) can see channel history messages; bots cannot (at least in telethon). Bots can only listen for channel **updates** only if they are one of its **administrators**.
The `client.iter_messages()` accepts other parameters like `min_id` which can be used to get messages only after a specific message (for example, we can save the last message id that we have processed and next time pass that id as `min_id` so only messages after that message are returned).

[1]: https://github.com/LonamiWebs/Telethon [2]: https://docs.telethon.dev/en/stable/basic/installation.html
Have you tried the other type of Telegram API: [Telegram \[client\] API and TDLib](https://core.telegram.org/#tdlib-build-your-own-telegram)?
Using [telethon library][1] makes it easy to read channels history (see [telethon docs][2]).
For this, we need an `api_id` and an `api_hash`. So, do the following:
1. Log in to your [Telegram core](https://my.telegram.org/) 2. Open the [API development tools area](https://my.telegram.org/apps) 3. Fill out the simple form there 4. Now you can receive your `api_id` and `api_hash`
See Telegram's help documentation about [how to get your API credentials](https://core.telegram.org/api/obtaining_api_id).
Here is an example code that gets the last *5* messages of *targetChannelId*:
```python from telethon import TelegramClient

API_ID = 123456 # See above for how to get it API_HASH = '123abc' # See above for how to get it client = TelegramClient('my-client', API_ID, API_HASH)

async def main(): async for message in client.iter_messages('targetChannelId', limit=5): print(message.id, message.text)

with client: client.loop.run_until_complete(main()) ```
The first time you run this code it asks your phone number or bot token. Enter your **phone number** in the format `+9912345...` where `99` is your country code and the rest is your phone number. It then may send a login code to your Telegram app; enter it in the console.
**Note**: Only users (phone numbers) can see channel history messages; bots cannot (at least in telethon). Bots can only listen for channel **updates** only if they are one of its **administrators**.
The `client.iter_messages()` accepts other parameters like `min_id` which can be used to get messages only after a specific message (for example, we can save the last message id that we have processed and next time pass that id as `min_id` so only messages after that message are returned).

[1]: https://github.com/LonamiWebs/Telethon [2]: https://docs.telethon.dev/en/stable/basic/installation.html

        
Present in both answers; Present only in the new answer; Present only in the old answer;