From 7c90c03ec2b1133d45e098aa3aca857804462be5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 17 Dec 2017 13:32:10 +0100 Subject: [PATCH] Created Getting Started (markdown) --- Getting-Started.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Getting-Started.md diff --git a/Getting-Started.md b/Getting-Started.md new file mode 100644 index 0000000..64dc411 --- /dev/null +++ b/Getting-Started.md @@ -0,0 +1,46 @@ +This section provides all the information you need to start using Pyrogram. There are a few steps you have to follow before you can use the library to make API calls. + +## API Keys + +The very first step requires you to obtain a valid Telegram API key. If you already have one you can skip this, otherwise: + +1. Visit https://my.telegram.org/apps and log in with your Telegram Account. +2. Fill out the form to register a new Telegram application. +3. Done. The Telegram API key consists of two parts: the **App api_id** and the **App api_hash**. + +**Important:** This key should be kept secret. + +## Setup + +Create a new `config.ini` file at the root of your working directory, paste the following and replace the **api_id** and **api_hash** values with [your own](#api-keys): + +``` ini +[pyrogram] +api_id = 12345 +api_hash = 0123456789abcdef0123456789abcdef +``` + +## Authorization + +Telegram requires that users be authorized in order to use the API. Pyrogram automatically manages this access, all you need to do is create an instance of the `pyrogram.Client` class by passing to it a `session_name` of your choice and call the `start` method: + +``` python +from pyrogram import Client + +client = Client(session_name="example") +client.start() +``` + +This starts an interactive shell asking you to input your **phone number** (including your [Country Code](https://en.wikipedia.org/wiki/List_of_country_calling_codes)) and the **phone code** you will receive: + +``` +Enter phone number: +39********** +Is "+39**********" correct? (y/n): y +Enter phone code: 32768 +``` + +After successfully authorizing yourself, a new file called `example.session` will be created allowing Pyrogram executing API calls with your identity. + +**Important:** The `*.session` file must be kept secret. + +**Note:** The authorization process is executed only once. However, the code above is always required; as soon as a valid session file exists, Pyrogram will use that and won't ask you to enter your phone number again when you restart your script. \ No newline at end of file