Update readme/docs

This commit is contained in:
Lonami Exo 2018-01-11 12:43:08 +01:00
parent 294aa814c2
commit 5c129d9b40
2 changed files with 20 additions and 5 deletions

View File

@ -29,11 +29,7 @@ Creating a client
phone = '+34600000000' phone = '+34600000000'
client = TelegramClient('session_name', api_id, api_hash) client = TelegramClient('session_name', api_id, api_hash)
client.connect() client.start()
# If you already have a previous 'session_name.session' file, skip this.
client.sign_in(phone=phone)
me = client.sign_in(code=77777) # Put whatever code you received here.
Doing stuff Doing stuff

View File

@ -76,6 +76,22 @@ As a full example:
me = client.sign_in(phone_number, input('Enter code: ')) me = client.sign_in(phone_number, input('Enter code: '))
All of this, however, can be done through a call to ``.start()``:
.. code-block:: python
client = TelegramClient('anon', api_id, api_hash)
client.start()
The code shown is just what ``.start()`` will be doing behind the scenes
(with a few extra checks), so that you know how to sign in case you want
to avoid using ``input()`` (the default) for whatever reason.
You can use either, as both will work. Determining which
is just a matter of taste, and how much control you need.
.. note:: .. note::
If you want to use a **proxy**, you have to `install PySocks`__ If you want to use a **proxy**, you have to `install PySocks`__
(via pip or manual) and then set the appropriated parameters: (via pip or manual) and then set the appropriated parameters:
@ -113,6 +129,9 @@ account, calling :meth:`telethon.TelegramClient.sign_in` will raise a
client.sign_in(password=getpass.getpass()) client.sign_in(password=getpass.getpass())
The mentioned ``.start()`` method will handle this for you as well, but
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: take as example the following code snippet: