问题描述
我正在制作一个python3应用程序以自动登录到Facebook,并持续监视每个线程中的传入消息,并在终端中显示它们,甚至保存在本地,但是我在登录时遇到了一些问题...
我制作了一个程序,用于在开头检查会话,如果会话存在,则使用会话登录,如果不存在,则使用凭据登录
该程序应该检查会话文件并使用它登录,如果会话文件不存在,则检查保存凭据的凭据文件并从文件中读取凭据,并使用它们登录,甚至凭据文件也可以。不存在,要求您在终端中输入凭据。
这是代码
from fbchat import Client
from fbchat.models import *
import fbchat
import getpass
import os
email = ""
password = ""
sessions = ""
userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko)
Chrome/44.0.2403.157 Safari/537.36"
class Main:
def __init__(self):
global email
global password
global sessions
global userAgent
if os.path.exists("session.txt"):
with open("session.txt","r") as fl:
sessions = fl.read()
fl.close()
Client.setSession(sessions)
print("Logged in via Sessions")
# check if logged in
if not Client.isLoggedIn(self):
print("Sessions not found or unable to login via Sessions")
if not os.path.exists("creds.txt"):
email = input("Email: ")
password = getpass.getpass("Password")
client = Client(email,password,user_agent=userAgent)
if client.isLoggedIn(self):
print("Logged in via entered credentials")
# get and save sessions
sessions = client.getSession()
client.setSession(sessions)
with open("session.txt","w") as fl:
fl.write(sessions)
fl.close()
fl = open("creds.txt","w")
fl.write(email + "\n" + password)
fl.close()
else:
fl = open("creds.txt","r")
crd = fl.read()
fl.close()
crd = crd.split("\n")[0]
email = crd[0]
password = crd[1]
client = Client(email,user_agent=userAgent)
if client.isLoggedIn(self):
print("Logged in via saved credentials")
# get and save sessions
sessions = client.getSession()
client.setSession(sessions)
with open("session.txt","w") as fl:
fl.write(sessions)
fl.close()
def error_creds(self):
if os.path.exists("creds.txt"):
os.remove("creds.txt")
Main()
def main(sefl):
# client = Client("chrishdev.chd@gmail.com",bytearray.fromhex("6368644063687269736864657640636864").decode() )
print(f"This is main... ")
if __name__ == '__main__':
Main().main()
Traceback (most recent call last):
File "/home/chd/projects/PycharmProjects/AntiUnsender/main.py",line 77,in <module>
Main().main()
File "/home/chd/projects/PycharmProjects/AntiUnsender/main.py",line 29,in __init__
if not Client.isLoggedIn(self):
File "/usr/local/lib/python3.8/dist-packages/fbchat/_client.py",line 154,in isLoggedIn
return self._state.is_logged_in()
AttributeError: 'Main' object has no attribute '_state'
帮我解决这个问题...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)