[英]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.