首页 > 解决方案 > telethon如何使用登录代码请求呼叫

问题描述

由于我正在编写一个客户端,我的美国朋友注意到代码不通过短信,而只是通过电话。但我不明白该怎么做,如何请求电话(

 await client.connect()


    code_settings = types.CodeSettings(
        current_number=True,
        allow_flashcall=False,
        allow_app_hash=False
    )
    result = await client(functions.auth.SendCodeRequest(
        phone_number=phone,
        api_id=api_id,
        api_hash=api_hash,
        settings=code_settings
    ))
    # time.sleep(10)
    result = await client(functions.auth.ResendCodeRequest(
        phone_number=phone,
        phone_code_hash=result.phone_code_hash
    ))
    # time.sleep(20)
    result = await client(functions.auth.ResendCodeRequest(
        phone_number=phone,
        phone_code_hash=result.phone_code_hash
    ))

    # result = await client(SentCodeTypeCall(5))
    # result = await client(functions.auth.)

    while not isinstance(result.type, SentCodeTypeCall):
        # time.sleep(10)
        result = await client(functions.auth.ResendCodeRequest(
            phone_number=phone,
            phone_code_hash=result.phone_code_hash
        ))
    # time.sleep(20)
    # await client(functions.auth.SendCodeRequest(
    #     phone_number=phone,
    #     api_id=api_id,
    #     api_hash=api_hash,
    #     settings=code_settings
    # ))

    def code_callback():
        code = input('Please enter the code you received: ')
        return code

    time.sleep(5)
    await client.start(phone=phone, code_callback=code_callback)

我认为这不是正确的代码。

我可以告诉 SendCode Request 方法立即调用而不发送 SMS 吗?

标签: telethon

解决方案


推荐阅读