mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 11:06:39 +00:00
Update docs regarding 2FA and getting entities by ID
This commit is contained in:
parent
6c9becb1ed
commit
04695d3657
@ -150,35 +150,9 @@ The mentioned ``.start()`` method will handle this for you as well, but
|
|||||||
you must set the ``password=`` parameter beforehand (it won't be asked).
|
you must set the ``password=`` parameter beforehand (it won't be asked).
|
||||||
|
|
||||||
If you don't have 2FA enabled, but you would like to do so through the library,
|
If you don't have 2FA enabled, but you would like to do so through the library,
|
||||||
take as example the following code snippet:
|
use :obj:`client.edit_2fa <telethon.telegram_client.TelegramClient.edit_2fa>`
|
||||||
|
for it. Be sure to know what you're doing when using this function and you
|
||||||
.. code-block:: python
|
won't run into any problems.
|
||||||
|
|
||||||
import os
|
|
||||||
from hashlib import sha256
|
|
||||||
from telethon.tl.functions import account
|
|
||||||
from telethon.tl.types.account import PasswordInputSettings
|
|
||||||
|
|
||||||
new_salt = client(account.GetPasswordRequest()).new_salt
|
|
||||||
salt = new_salt + os.urandom(8) # new random salt
|
|
||||||
|
|
||||||
pw = 'secret'.encode('utf-8') # type your new password here
|
|
||||||
hint = 'hint'
|
|
||||||
|
|
||||||
pw_salted = salt + pw + salt
|
|
||||||
pw_hash = sha256(pw_salted).digest()
|
|
||||||
|
|
||||||
result = client(account.UpdatePasswordSettingsRequest(
|
|
||||||
current_password_hash=salt,
|
|
||||||
new_settings=PasswordInputSettings(
|
|
||||||
new_salt=salt,
|
|
||||||
new_password_hash=pw_hash,
|
|
||||||
hint=hint
|
|
||||||
)
|
|
||||||
))
|
|
||||||
|
|
||||||
Thanks to `Issue 259 <https://github.com/LonamiWebs/Telethon/issues/259>`_
|
|
||||||
for the tip!
|
|
||||||
|
|
||||||
|
|
||||||
__ https://github.com/Anorov/PySocks#installation
|
__ https://github.com/Anorov/PySocks#installation
|
||||||
|
@ -32,7 +32,7 @@ you're able to just do this:
|
|||||||
# Dialogs are the "conversations you have open".
|
# Dialogs are the "conversations you have open".
|
||||||
# This method returns a list of Dialog, which
|
# This method returns a list of Dialog, which
|
||||||
# has the .entity attribute and other information.
|
# has the .entity attribute and other information.
|
||||||
dialogs = client.get_dialogs(limit=200)
|
dialogs = client.get_dialogs()
|
||||||
|
|
||||||
# All of these work and do the same.
|
# All of these work and do the same.
|
||||||
lonami = client.get_entity('lonami')
|
lonami = client.get_entity('lonami')
|
||||||
@ -44,27 +44,18 @@ you're able to just do this:
|
|||||||
contact = client.get_entity('+34xxxxxxxxx')
|
contact = client.get_entity('+34xxxxxxxxx')
|
||||||
friend = client.get_entity(friend_id)
|
friend = client.get_entity(friend_id)
|
||||||
|
|
||||||
# Using Peer/InputPeer (note that the API may return these)
|
# Getting entities through their ID (User, Chat or Channel)
|
||||||
# users, chats and channels may all have the same ID, so it's
|
entity = client.get_entity(some_id)
|
||||||
# necessary to wrap (at least) chat and channels inside Peer.
|
|
||||||
#
|
# You can be more explicit about the type for said ID by wrapping
|
||||||
# NOTICE how the IDs *must* be wrapped inside a Peer() so the
|
# it inside a Peer instance. This is recommended but not necessary.
|
||||||
# library knows their type.
|
|
||||||
from telethon.tl.types import PeerUser, PeerChat, PeerChannel
|
from telethon.tl.types import PeerUser, PeerChat, PeerChannel
|
||||||
|
|
||||||
my_user = client.get_entity(PeerUser(some_id))
|
my_user = client.get_entity(PeerUser(some_id))
|
||||||
my_chat = client.get_entity(PeerChat(some_id))
|
my_chat = client.get_entity(PeerChat(some_id))
|
||||||
my_channel = client.get_entity(PeerChannel(some_id))
|
my_channel = client.get_entity(PeerChannel(some_id))
|
||||||
|
|
||||||
|
|
||||||
.. warning::
|
|
||||||
|
|
||||||
As it has been mentioned already, getting the entity of a channel
|
|
||||||
through e.g. ``client.get_entity(channel id)`` will **not** work.
|
|
||||||
You would use ``client.get_entity(types.PeerChannel(channel id))``.
|
|
||||||
Remember that supergroups are channels and normal groups are chats.
|
|
||||||
This is a common mistake!
|
|
||||||
|
|
||||||
|
|
||||||
All methods in the :ref:`telegram-client` call ``.get_input_entity()`` prior
|
All methods in the :ref:`telegram-client` call ``.get_input_entity()`` prior
|
||||||
to sending the requst to save you from the hassle of doing so manually.
|
to sending the requst to save you from the hassle of doing so manually.
|
||||||
That way, convenience calls such as ``client.send_message('lonami', 'hi!')``
|
That way, convenience calls such as ``client.send_message('lonami', 'hi!')``
|
||||||
|
Loading…
Reference in New Issue
Block a user