使用第一个代码运行会创建一个会话文件并运行它。使用此文件运行第二个代码,会话将不起作用。
第一个代码
import telethon
from telethon import tl
from telethon import TelegramClient
import logging
def update_handler(update_object):
print(update_object)
phone_number='*'
client = telethon.TelegramClient('sweet',api_id = *,api_hash = '*')
client.connect()
print('connected')
if not client.is_user_authorized():
client.send_code_request(phone_number)
me = client.sign_in(phone_number, input('Enter code: '))
print(client.get_me())
print(me.stringify())
输出:
连接的
输入代码:85813
用户(is_self=True,contact=True,mutual_contact=False,deleted=False,bot=False,bot_chat_history=False,bot_nochats=False,verified=False,restricted=False,min=False,bot_inline_geo=False,id= ,access_hash =- ,first_name='-',last_name=None,username=None,phone='*',photo=None,status=UserStatusOnline(expires=datetime.utcfromtimestamp(1515302772)),bot_info_version=None,restriction_reason=None,bot_inline_placeholder =无,lang_code=无)
用户(is_self=True,contact=True,mutual_contact=False,deleted=False,bot=False,bot_chat_history=False,bot_nochats=False,verified=False,restricted=False,min=False,bot_inline_geo=False,id= ,access_hash =- ,first_name='-',last_name=None,username=None,phone='*',photo=None,status=UserStatusOnline(expires=datetime.utcfromtimestamp(1515302772)),bot_info_version=None,restriction_reason=None,bot_inline_placeholder =无,lang_code=无)
第二个代码
import telethon
from telethon import tl
from telethon import TelegramClient
import logging
def update_handler(update_object):
print(update_object)
phone_number='**'
client = telethon.TelegramClient('sweet',api_id = *,api_hash = '*')
client.connect()
print('connected')
print(client.get_me())
输出:
None