[英]How to convert tdata to telethon session?
I need to convert telegram data to telethon session.我需要将电报数据转换为电视节目 session。 How can i do this?我怎样才能做到这一点? I tried to find a solution, spent three days, but I didn't find anything我试图找到解决方案,花了三天时间,但我没有找到任何东西
It's been nearly two years, but there's now a Python library called opentele created to do this.已经快两年了,但现在创建了一个名为opentele的 Python 库来执行此操作。
Assuming you already have Python knowledge, please follow the steps below.假设您已经具备 Python 知识,请按照以下步骤操作。
pip install opentele pip 安装opentele
tdata
folder that is already authorized (have at least one logged-in account).您需要有一个已授权的tdata
文件夹(至少有一个登录帐户)。tdata
folder on Windows is located at %appdata%\Telegram Desktop\tdata
. Windows 上tdata
文件夹的默认路径位于%appdata%\Telegram Desktop\tdata
。 from opentele.td import TDesktop from opentele.tl import TelegramClient from opentele.api import API, UseCurrentSession, CreateNewSession import asyncio
async def main(): # PUT EXAMPLE CODE HERE asyncio.run(main())
tdata
folder into a TDesktop
object:将tdata
文件夹加载到TDesktop
object 中: # Load TDesktop client from tdata folder tdataFolder = r"C:\Users\<username>\AppData\Roaming\Telegram Desktop\tdata" tdesk = TDesktop(tdataFolder) # Check if we have loaded any accounts assert tdesk.isLoaded()
There are two ways you can do this, either by using the current session or creating (login to) a new session.有两种方法可以做到这一点,要么使用当前的 session,要么创建(登录)新的 session。
# flag=UseCurrentSession # # Convert TDesktop to Telethon using the current session. client = await tdesk.ToTelethon(session="telethon.session", flag=UseCurrentSession)
# flag=CreateNewSession # # Convert TDesktop to Telethon by creating a new session. # CreateNewSession will use the current session (in tdata folder) to authorize a new session using QR Login. # If 2FA is enabled for this account, you must specify the password via the password argument. # This is of course slower than UseCurrentSession. client = await tdesk.ToTelethon(session="telethon.session", flag=CreateNewSession)
# Connect and print all logged-in sessions of this client.
# Telethon will save the session to telethon.session on creation.
await client.connect()
await client.PrintSessions()
from opentele.td import TDesktop
from opentele.tl import TelegramClient
from opentele.api import API, UseCurrentSession
import asyncio
async def main():
# Load TDesktop client from tdata folder
tdataFolder = r"C:\Users\<username>\AppData\Roaming\Telegram Desktop\tdata"
tdesk = TDesktop(tdataFolder)
# Check if we have loaded any accounts
assert tdesk.isLoaded()
# flag=UseCurrentSession
#
# Convert TDesktop to Telethon using the current session.
client = await tdesk.ToTelethon(session="telethon.session", flag=UseCurrentSession)
# Connect and print all logged-in sessions of this client.
# Telethon will save the session to telethon.session on creation.
await client.connect()
await client.PrintSessions()
asyncio.run(main())
telethon.session
file. session 将保存到telethon.session
文件。telethon.session
with telethon, or use it directly with opentele - which is recommended because you don't need your own API_ID
and API_HASH
, the library by default will use Official Telegram API.您可以将此telethon.session
与 telethon 一起使用,或直接与opentele一起使用 - 建议您这样做,因为您不需要自己的API_ID
和API_HASH
,该库默认使用官方 Telegram API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.