mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2024-12-05 22:45:18 +01:00
232 lines
15 KiB
HTML
232 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html class="">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Takeout API</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta property="description" content="Telegram's API allows users to export all of their information through the takeout API.">
|
|
<meta property="og:title" content="Takeout API">
|
|
<meta property="og:image" content="">
|
|
<meta property="og:description" content="Telegram's API allows users to export all of their information through the takeout API.">
|
|
<link rel="icon" type="image/svg+xml" href="/img/website_icon.svg?4">
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
|
|
<link rel="alternate icon" href="/img/favicon.ico" type="image/x-icon" />
|
|
<link href="/css/bootstrap.min.css?3" rel="stylesheet">
|
|
|
|
<link href="/css/telegram.css?238" rel="stylesheet" media="screen">
|
|
<style>
|
|
</style>
|
|
</head>
|
|
<body class="preload">
|
|
<div class="dev_page_wrap">
|
|
<div class="dev_page_head navbar navbar-static-top navbar-tg">
|
|
<div class="navbar-inner">
|
|
<div class="container clearfix">
|
|
<ul class="nav navbar-nav navbar-right hidden-xs"><li class="navbar-twitter"><a href="https://twitter.com/telegram" target="_blank" data-track="Follow/Twitter" onclick="trackDlClick(this, event)"><i class="icon icon-twitter"></i><span> Twitter</span></a></li></ul>
|
|
<ul class="nav navbar-nav">
|
|
<li><a href="//telegram.org/">Home</a></li>
|
|
<li class="hidden-xs"><a href="//telegram.org/faq">FAQ</a></li>
|
|
<li class="hidden-xs"><a href="//telegram.org/apps">Apps</a></li>
|
|
<li class="active"><a href="/api">API</a></li>
|
|
<li class=""><a href="/mtproto">Protocol</a></li>
|
|
<li class=""><a href="/schema">Schema</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="container clearfix">
|
|
<div class="dev_page">
|
|
<div id="dev_page_content_wrap" class=" ">
|
|
<div class="dev_page_bread_crumbs"><ul class="breadcrumb clearfix"><li><a href="/api" >API</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/api/takeout" >Takeout API</a></li></ul></div>
|
|
<h1 id="dev_page_title">Takeout API</h1>
|
|
|
|
<div id="dev_page_content"><!-- scroll_nav -->
|
|
|
|
<p>Telegram's API allows users to export all of their information through the takeout API.</p>
|
|
<pre><code><a href='/constructor/account.takeout'>account.takeout</a>#4dba4501 id:<a href='/type/long'>long</a> = <a href='/type/account.Takeout'>account.Takeout</a>;
|
|
|
|
<a href='/constructor/inputTakeoutFileLocation'>inputTakeoutFileLocation</a>#29be5899 = <a href='/type/InputFileLocation'>InputFileLocation</a>;
|
|
|
|
---functions---
|
|
|
|
<a href='/method/account.initTakeoutSession'>account.initTakeoutSession</a>#8ef3eab0 flags:<a href='/type/%23'>#</a> contacts:flags.0?<a href='/constructor/true'>true</a> message_users:flags.1?<a href='/constructor/true'>true</a> message_chats:flags.2?<a href='/constructor/true'>true</a> message_megagroups:flags.3?<a href='/constructor/true'>true</a> message_channels:flags.4?<a href='/constructor/true'>true</a> files:flags.5?<a href='/constructor/true'>true</a> file_max_size:flags.5?<a href='/type/long'>long</a> = <a href='/type/account.Takeout'>account.Takeout</a>;
|
|
|
|
invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X;
|
|
|
|
<a href='/method/account.finishTakeoutSession'>account.finishTakeoutSession</a>#1d2652ee flags:<a href='/type/%23'>#</a> success:flags.0?<a href='/constructor/true'>true</a> = <a href='/type/Bool'>Bool</a>;</code></pre>
|
|
<p>Use <a href="/method/account.initTakeoutSession">account.initTakeoutSession</a> to initialize a takeout session: pass the appropriate flags to enable usage of the corresponding methods, as described below. </p>
|
|
<p>When invoking the methods described below, each query must be wrapped using <a href="/method/invokeWithTakeout">invokeWithTakeout</a>, with the <code>id</code> returned by <a href="/method/account.initTakeoutSession">account.initTakeoutSession</a>. </p>
|
|
<p>After finishing the export, terminate the session using <a href="/method/account.finishTakeoutSession">account.finishTakeoutSession</a>. </p>
|
|
<h3><a class="anchor" href="#split-ranges" id="split-ranges" name="split-ranges"><i class="anchor-icon"></i></a>Split ranges</h3>
|
|
<pre><code><a href='/constructor/messageRange'>messageRange</a>#ae30253 min_id:<a href='/type/int'>int</a> max_id:<a href='/type/int'>int</a> = <a href='/type/MessageRange'>MessageRange</a>;
|
|
|
|
---functions---
|
|
|
|
<a href='/method/messages.getSplitRanges'>messages.getSplitRanges</a>#1cff7e08 = <a href='/type/Vector%20t'>Vector</a><<a href='/type/MessageRange'>MessageRange</a>>;
|
|
|
|
invokeWithMessagesRange#365275f2 {X:Type} range:MessageRange query:!X = X;</code></pre>
|
|
<p>Some method calls require additional pagination using message ranges. </p>
|
|
<p>First of all, obtain a list of message ranges by invoking <a href="/method/messages.getSplitRanges">messages.getSplitRanges</a> (wrapping it in an <a href="/method/invokeWithTakeout">invokeWithTakeout</a> as usual). </p>
|
|
<p>Then, when invoking methods that require message range pagination, wrap the method using <a href="/method/invokeWithMessagesRange">invokeWithMessagesRange</a>, before also wrapping it in an <a href="/method/invokeWithTakeout">invokeWithTakeout</a> as usual. </p>
|
|
<p>Start by passing the first message range; continue passing the same message range while paginating using the <a href="/api/offsets">usual <code>offset_*</code>, <code>limit</code>, etc parameters</a>; once there are no more results left, switch to the next message range, re-starting <code>offset_*</code>, <code>limit</code> pagination from the beginning.<br>
|
|
Repeat until you've finished all the message ranges that were returned by <a href="/method/messages.getSplitRanges">messages.getSplitRanges</a>. </p>
|
|
<h3><a class="anchor" href="#procedure" id="procedure" name="procedure"><i class="anchor-icon"></i></a>Procedure</h3>
|
|
<p>Example implementation: <a href="https://github.com/telegramdesktop/tdesktop/tree/dev/Telegram/SourceFiles/export">tdesktop</a>. </p>
|
|
<p>Here's an overview of the steps required to export account information. </p>
|
|
<p>All requests must be wrapped in an <a href="/method/invokeWithTakeout">invokeWithTakeout</a> constructors, including <a href="/method/upload.getFile">upload.getFile</a> calls to save files. </p>
|
|
<p>Unless otherwise specified, all requests do <strong>not</strong> require pagination using <a href="#split-ranges">split ranges</a>. </p>
|
|
<ul>
|
|
<li>
|
|
<p>If the user wants to download messages from chats, groups or channels:</p>
|
|
<ul>
|
|
<li>
|
|
<p>First of all, fetch and save the dialog list using <a href="#split-ranges">split ranges</a> and <a href="/method/messages.getDialogs">messages.getDialogs</a>; at the beginning of each split range, make an initial request with all offsets set to <code>0</code> and <code>limit=1</code> to fetch total dialog <code>count</code> to display a proper progress bar. </p>
|
|
</li>
|
|
<li>
|
|
<p><a href="#left-channels">Request and save info about left channels and supergroups</a> if the user wants to export channel and group messages. </p>
|
|
</li>
|
|
<li>
|
|
<p>For all dialogs, check if they match the dialog types chosen by the user, and if yes download all messages using <a href="#split-ranges">split ranges</a> and <a href="/method/messages.getHistory">messages.getHistory</a>; for each split range, make an initial request with all offsets set to <code>0</code> and <code>limit=1</code> to fetch the initial message count to display a proper progress bar.<br>
|
|
Use the single message returned by the initial <code>limit=1</code> request to also skip ranges that don't have any messages, because an empty <code>messages</code> vector or a single <a href="/constructor/messageEmpty">messageEmpty</a> is returned.<br>
|
|
If the user also chose to download only messages within a specific date interval, skip ranges whose:</p>
|
|
<ul>
|
|
<li>Last message (returned by that same initial <code>limit=1</code> call) has a <code>date</code> bigger than the top of the specified date interval.</li>
|
|
<li>First message (returned by a new call to <a href="/method/messages.getHistory">messages.getHistory</a> with <code>limit=1</code>, <code>offset_id=1</code>, <code>add_offset=-1</code>) has a <code>date</code> smaller than the bottom of the specified date interval. </li>
|
|
</ul>
|
|
<p>For each downloaded and saved message, also download and save all attached media, including <a href="/api/custom-emoji">custom emojis</a> present in messages and captions, respecting the per-file download filesize limits imposed by the user. </p>
|
|
<p>If the user chose to download only their own messages, not messages sent by other users, use <a href="/method/messages.search">messages.search</a> with <code>peer</code> set to <a href="/constructor/inputPeerSelf">inputPeerSelf</a> instead of <a href="/method/messages.getHistory">messages.getHistory</a>. </p>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>If the user wants to export their <a href="/api/stories">stories</a>:</p>
|
|
<ul>
|
|
<li>Use <a href="/method/stories.getStoriesArchive">stories.getStoriesArchive</a> to fetch, download and store all posted stories, including <a href="/api/custom-emoji">custom emojis</a> present in captions.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>If the user wants to export personal info:</p>
|
|
<ul>
|
|
<li>Invoke and store the result of <a href="/method/users.getFullUser">users.getFullUser</a> with <a href="/constructor/inputUserSelf">inputUserSelf</a>.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>If the user wants to export their own profile pictures:</p>
|
|
<ul>
|
|
<li>Invoke <a href="/method/photos.getUserPhotos">photos.getUserPhotos</a> to fetch the list of and download all profile pictures.</li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>If the user wants to export their contact list: </p>
|
|
<ul>
|
|
<li>See <a href="#contacts">here »</a></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>If the user wants to export their sessions: </p>
|
|
<ul>
|
|
<li>Invoke and store the result of <a href="/method/account.getAuthorizations">account.getAuthorizations</a> and <a href="/method/account.getWebAuthorizations">account.getWebAuthorizations</a></li>
|
|
</ul>
|
|
</li>
|
|
<li>
|
|
<p>If the user wants to export any other data not mentioned above, like for example personal data related to new Telegram features, that do not have any specific takeout methods in the Takeout API yet.</p>
|
|
<ul>
|
|
<li>Use <a href="/method/upload.getFile">upload.getFile</a> with <a href="/constructor/inputTakeoutFileLocation">inputTakeoutFileLocation</a>; this will download a JSON file that will contain all personal data related to features that do not have a specialized takeout method yet.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h4><a class="anchor" href="#contacts" id="contacts" name="contacts"><i class="anchor-icon"></i></a>Contacts</h4>
|
|
<pre><code><a href='/constructor/savedPhoneContact'>savedPhoneContact</a>#1142bd56 phone:<a href='/type/string'>string</a> first_name:<a href='/type/string'>string</a> last_name:<a href='/type/string'>string</a> date:<a href='/type/int'>int</a> = <a href='/type/SavedContact'>SavedContact</a>;
|
|
|
|
---functions---
|
|
|
|
<a href='/method/contacts.getSaved'>contacts.getSaved</a>#82f1e39f = <a href='/type/Vector%20t'>Vector</a><<a href='/type/SavedContact'>SavedContact</a>>;</code></pre>
|
|
<p>This method does <strong>not</strong> require pagination using <a href="#split-ranges">message ranges</a>. </p>
|
|
<p>Use <a href="/method/contacts.getSaved">contacts.getSaved</a> to export the full contact list, see <a href="/api/contacts#fetching-the-contact-list">here »</a> for another alternative method that may be used to fetch the full list of all contacts with a Telegram account, without using a takeout session.</p>
|
|
<h4><a class="anchor" href="#left-channels" id="left-channels" name="left-channels"><i class="anchor-icon"></i></a>Left channels</h4>
|
|
<pre><code><a href='/constructor/messages.chats'>messages.chats</a>#64ff9fd5 chats:<a href='/type/Vector%20t'>Vector</a><<a href='/type/Chat'>Chat</a>> = <a href='/type/messages.Chats'>messages.Chats</a>;
|
|
<a href='/constructor/messages.chatsSlice'>messages.chatsSlice</a>#9cd81144 count:<a href='/type/int'>int</a> chats:<a href='/type/Vector%20t'>Vector</a><<a href='/type/Chat'>Chat</a>> = <a href='/type/messages.Chats'>messages.Chats</a>;
|
|
|
|
---functions---
|
|
|
|
<a href='/method/channels.getLeftChannels'>channels.getLeftChannels</a>#8341ecc0 offset:<a href='/type/int'>int</a> = <a href='/type/messages.Chats'>messages.Chats</a>;</code></pre>
|
|
<p>This method does <strong>not</strong> require pagination using <a href="#split-ranges">message ranges</a>. </p>
|
|
<p>Use <a href="/method/channels.getLeftChannels">channels.getLeftChannels</a> to get a list of channels or supergroups we left.</p></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="footer_wrap">
|
|
<div class="footer_columns_wrap footer_desktop">
|
|
<div class="footer_column footer_column_telegram">
|
|
<h5>Telegram</h5>
|
|
<div class="footer_telegram_description"></div>
|
|
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.
|
|
</div>
|
|
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/faq">About</a></h5>
|
|
<ul>
|
|
<li><a href="//telegram.org/faq">FAQ</a></li>
|
|
<li><a href="//telegram.org/privacy">Privacy</a></li>
|
|
<li><a href="//telegram.org/press">Press</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/apps#mobile-apps">Mobile Apps</a></h5>
|
|
<ul>
|
|
<li><a href="//telegram.org/dl/ios">iPhone/iPad</a></li>
|
|
<li><a href="//telegram.org/android">Android</a></li>
|
|
<li><a href="//telegram.org/dl/web">Mobile Web</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/apps#desktop-apps">Desktop Apps</a></h5>
|
|
<ul>
|
|
<li><a href="//desktop.telegram.org/">PC/Mac/Linux</a></li>
|
|
<li><a href="//macos.telegram.org/">macOS</a></li>
|
|
<li><a href="//telegram.org/dl/web">Web-browser</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer_column footer_column_platform">
|
|
<h5><a href="/">Platform</a></h5>
|
|
<ul>
|
|
<li><a href="/api">API</a></li>
|
|
<li><a href="//translations.telegram.org/">Translations</a></li>
|
|
<li><a href="//instantview.telegram.org/">Instant View</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="footer_columns_wrap footer_mobile">
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/faq">About</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/blog">Blog</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/apps">Apps</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="/">Platform</a></h5>
|
|
</div>
|
|
<div class="footer_column">
|
|
<h5><a href="//telegram.org/press">Press</a></h5>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="/js/main.js?47"></script>
|
|
<script src="/js/jquery.min.js?1"></script>
|
|
<script src="/js/bootstrap.min.js?1"></script>
|
|
|
|
<script>window.initDevPageNav&&initDevPageNav();
|
|
backToTopInit("Go up");
|
|
removePreloadInit();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|