0

I am trying to send messages to Facebook friends via Messenger. I found a tutorial & tried it.

import fbchat 
from getpass import getpass 
username = str(raw_input("Username: ")) 
client = fbchat.Client(username, getpass()) 
no_of_friends = int(raw_input("Number of friends: ")) 
for i in xrange(no_of_friends): 
    name = str(raw_input("Name: ")) 
    friends = client.getUsers(name) # return a list of names 
    friend = friends[0] 
    msg = str(raw_input("Message: ")) 
    sent = client.send(friend.uid, msg) 
    if sent: 
        print("Message sent successfully!")

When I ran the program, it requested me my password. And, of course, I entered it. But Facebook doesn't accept the request from my program & lock my Facebook account. I think this is due to security reasons. Then how can I log in to my Facebook from python program without getting locked? Thanks.

Jeremy Gillbert
  • 133
  • 2
  • 10
  • _“Then how can I log in to my Facebook from python program without getting locked?”_ - you’re not supposed to do that at all. _“I am trying to send messages to Facebook friends via Messenger.”_ - use the web UI, or one of the native apps then …? Why would there be any reason to try and “automate” this using external tools in the first place? – CBroe Jul 20 '20 at 06:42

1 Answers1

1

This seems like the issue lies with your library, not with you. You should make a new issue at their github page. https://github.com/carpedm20/fbchat

You can selenium to remotely control the browser and do stuff a normal user can do, including logging into facebook.

WyattBlue
  • 591
  • 1
  • 5
  • 21