[英]How to convert tdata to telethon session?
我需要将电报数据转换为电视节目 session。 我怎样才能做到这一点? 我试图找到解决方案,花了三天时间,但我没有找到任何东西
已经快两年了,但现在创建了一个名为opentele的 Python 库来执行此操作。
假设您已经具备 Python 知识,请按照以下步骤操作。
pip 安装opentele
tdata
文件夹(至少有一个登录帐户)。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
文件夹加载到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()
有两种方法可以做到这一点,要么使用当前的 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
文件。telethon.session
与 telethon 一起使用,或直接与opentele一起使用 - 建议您这样做,因为您不需要自己的API_ID
和API_HASH
,该库默认使用官方 Telegram API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.