如何使用Pyrogram登录Telegram?

huangapple go评论61阅读模式
英文:

How to log in to telegram using pyrogram?

问题

请帮忙,在第一次运行时,我执行了send_code()函数并保存了phone_code_hash,在第二次运行时,我使用来自Telegram的代码和从send_code函数中保存的散列代码执行了main(),但在sign_in时,我收到一个代码已过期的错误,尽管所有数据都是正确的。

英文:

Please help, on the first run, I executed the send_code() function and saved the phone_code_hash, on the second run, I executed main() with the code received from the telegram and the hash code saved from the send_code function, but when sign_in I get an error that the code has expired, although all data is correct.

client = Client(
        'sessin', 
        api_id=app_id, 
        api_hash=app_hash,
    )

async def send_code(phone_number):
    await client.connect()
    result = await client.send_code(phone_number)
    phone_code_hash = result.phone_code_hash


async def main(phone_number, phone_code, phone_hash_code):
    await client.connect()
    result = await client.sign_in(phone_number=phone_number, phone_code=phone_code, phone_code_hash=phone_hash_code)

I tried to find information but didn't find it.

答案1

得分: 0

以下是使用Pyrogram登录的示例代码:

client = Client("sessions", api_id, api_hash)

client.connect()

sent_code = client.send_code(phone)

code = input("Enter the code : ")

signed_in = client.sign_in(phone, sent_code.phone_code_hash, code)

client.disconnect()
英文:

Here is example to login with pyrogram.

client = Client("sessions", api_id, api_hash)

client.connect()

sent_code = client.send_code(phone)

code = input("Enter the code : ")

signed_in = client.sign_in(phone, sent_code.phone_code_hash, code)

client.disconnect()

huangapple
  • 本文由 发表于 2023年2月27日 02:18:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定